Back to index

d-push  2.0
settings.php
Go to the documentation of this file.
00001 <?php
00002 /***********************************************
00003 * File      :   settings.php
00004 * Project   :   Z-Push
00005 * Descr     :   Provides the SETTINGS command
00006 *
00007 * Created   :   16.02.2012
00008 *
00009 * Copyright 2007 - 2012 Zarafa Deutschland GmbH
00010 *
00011 * This program is free software: you can redistribute it and/or modify
00012 * it under the terms of the GNU Affero General Public License, version 3,
00013 * as published by the Free Software Foundation with the following additional
00014 * term according to sec. 7:
00015 *
00016 * According to sec. 7 of the GNU Affero General Public License, version 3,
00017 * the terms of the AGPL are supplemented with the following terms:
00018 *
00019 * "Zarafa" is a registered trademark of Zarafa B.V.
00020 * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
00021 * The licensing of the Program under the AGPL does not imply a trademark license.
00022 * Therefore any rights, title and interest in our trademarks remain entirely with us.
00023 *
00024 * However, if you propagate an unmodified version of the Program you are
00025 * allowed to use the term "Z-Push" to indicate that you distribute the Program.
00026 * Furthermore you may use our trademarks where it is necessary to indicate
00027 * the intended purpose of a product or service provided you use it in accordance
00028 * with honest practices in industrial or commercial matters.
00029 * If you want to propagate modified versions of the Program under the name "Z-Push",
00030 * you may only do so if you have a written permission by Zarafa Deutschland GmbH
00031 * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
00032 *
00033 * This program is distributed in the hope that it will be useful,
00034 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00036 * GNU Affero General Public License for more details.
00037 *
00038 * You should have received a copy of the GNU Affero General Public License
00039 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00040 *
00041 * Consult LICENSE file for details
00042 ************************************************/
00043 
00044 class Settings extends RequestProcessor {
00045 
00054     public function Handle($commandCode) {
00055         if (!self::$decoder->getElementStartTag(SYNC_SETTINGS_SETTINGS))
00056             return false;
00057 
00058         //save the request parameters
00059         $request = array();
00060 
00061         // Loop through properties. Possible are:
00062         // - Out of office
00063         // - DevicePassword
00064         // - DeviceInformation
00065         // - UserInformation
00066         // Each of them should only be once per request. Each property must be processed in order.
00067         while (1) {
00068             $propertyName = "";
00069             if (self::$decoder->getElementStartTag(SYNC_SETTINGS_OOF)) {
00070                 $propertyName = SYNC_SETTINGS_OOF;
00071             }
00072             if (self::$decoder->getElementStartTag(SYNC_SETTINGS_DEVICEPW)) {
00073                 $propertyName = SYNC_SETTINGS_DEVICEPW;
00074             }
00075             if (self::$decoder->getElementStartTag(SYNC_SETTINGS_DEVICEINFORMATION)) {
00076                 $propertyName = SYNC_SETTINGS_DEVICEINFORMATION;
00077             }
00078             if (self::$decoder->getElementStartTag(SYNC_SETTINGS_USERINFORMATION)) {
00079                 $propertyName = SYNC_SETTINGS_USERINFORMATION;
00080             }
00081             //TODO - check if it is necessary
00082             //no property name available - break
00083             if (!$propertyName)
00084                 break;
00085 
00086             //the property name is followed by either get or set
00087             if (self::$decoder->getElementStartTag(SYNC_SETTINGS_GET)) {
00088                 //get is only available for OOF and user information
00089                 switch ($propertyName) {
00090                     case SYNC_SETTINGS_OOF:
00091                         $oofGet = new SyncOOF();
00092                         $oofGet->Decode(self::$decoder);
00093                         if(!self::$decoder->getElementEndTag())
00094                             return false; // SYNC_SETTINGS_GET
00095                         break;
00096 
00097                     case SYNC_SETTINGS_USERINFORMATION:
00098                         $userInformation = new SyncUserInformation();
00099                         break;
00100 
00101                     default:
00102                         //TODO: a special status code needed?
00103                         ZLog::Write(LOGLEVEL_WARN, sprintf ("This property ('%s') is not allowed to use get in request", $propertyName));
00104                 }
00105             }
00106             elseif (self::$decoder->getElementStartTag(SYNC_SETTINGS_SET)) {
00107                 //set is available for OOF, device password and device information
00108                 switch ($propertyName) {
00109                     case SYNC_SETTINGS_OOF:
00110                         $oofSet = new SyncOOF();
00111                         $oofSet->Decode(self::$decoder);
00112                         //TODO check - do it after while(1) finished?
00113                         break;
00114 
00115                     case SYNC_SETTINGS_DEVICEPW:
00116                         //TODO device password
00117                         $devicepassword = new SyncDevicePassword();
00118                         $devicepassword->Decode(self::$decoder);
00119                         break;
00120 
00121                     case SYNC_SETTINGS_DEVICEINFORMATION:
00122                         $deviceinformation = new SyncDeviceInformation();
00123                         $deviceinformation->Decode(self::$decoder);
00124                         self::$deviceManager->SaveDeviceInformation($deviceinformation);
00125                         break;
00126 
00127                     default:
00128                         //TODO: a special status code needed?
00129                         ZLog::Write(LOGLEVEL_WARN, sprintf ("This property ('%s') is not allowed to use set in request", $propertyName));
00130                 }
00131 
00132                 if(!self::$decoder->getElementEndTag())
00133                     return false; // SYNC_SETTINGS_SET
00134             }
00135             else {
00136                 ZLog::Write(LOGLEVEL_WARN, sprintf("Neither get nor set found for property '%s'", $propertyName));
00137                 return false;
00138             }
00139 
00140             if(!self::$decoder->getElementEndTag())
00141                 return false; // SYNC_SETTINGS_OOF or SYNC_SETTINGS_DEVICEPW or SYNC_SETTINGS_DEVICEINFORMATION or SYNC_SETTINGS_USERINFORMATION
00142 
00143             //break if it reached the endtag
00144             $e = self::$decoder->peek();
00145             if($e[EN_TYPE] == EN_TYPE_ENDTAG) {
00146                 self::$decoder->getElementEndTag(); //SYNC_SETTINGS_SETTINGS
00147                 break;
00148             }
00149         }
00150 
00151         $status = SYNC_SETTINGSSTATUS_SUCCESS;
00152 
00153         //TODO put it in try catch block
00154         //TODO implement Settings in the backend
00155         //TODO save device information in device manager
00156         //TODO status handling
00157 //        $data = self::$backend->Settings($request);
00158 
00159         self::$encoder->startWBXML();
00160         self::$encoder->startTag(SYNC_SETTINGS_SETTINGS);
00161 
00162             self::$encoder->startTag(SYNC_SETTINGS_STATUS);
00163             self::$encoder->content($status);
00164             self::$encoder->endTag(); //SYNC_SETTINGS_STATUS
00165 
00166             //get oof settings
00167             if (isset($oofGet)) {
00168                 $oofGet = self::$backend->Settings($oofGet);
00169                 self::$encoder->startTag(SYNC_SETTINGS_OOF);
00170                     self::$encoder->startTag(SYNC_SETTINGS_STATUS);
00171                     self::$encoder->content($oofGet->Status);
00172                     self::$encoder->endTag(); //SYNC_SETTINGS_STATUS
00173 
00174                     self::$encoder->startTag(SYNC_SETTINGS_GET);
00175                         $oofGet->Encode(self::$encoder);
00176                     self::$encoder->endTag(); //SYNC_SETTINGS_GET
00177                 self::$encoder->endTag(); //SYNC_SETTINGS_OOF
00178             }
00179 
00180             //get user information
00181             //TODO none email address found
00182             if (isset($userInformation)) {
00183                 self::$backend->Settings($userInformation);
00184                 self::$encoder->startTag(SYNC_SETTINGS_USERINFORMATION);
00185                     self::$encoder->startTag(SYNC_SETTINGS_STATUS);
00186                     self::$encoder->content($userInformation->Status);
00187                     self::$encoder->endTag(); //SYNC_SETTINGS_STATUS
00188 
00189                     self::$encoder->startTag(SYNC_SETTINGS_GET);
00190                         $userInformation->Encode(self::$encoder);
00191                     self::$encoder->endTag(); //SYNC_SETTINGS_GET
00192                 self::$encoder->endTag(); //SYNC_SETTINGS_USERINFORMATION
00193             }
00194 
00195             //set out of office
00196             if (isset($oofSet)) {
00197                 $oofSet = self::$backend->Settings($oofSet);
00198                 self::$encoder->startTag(SYNC_SETTINGS_OOF);
00199                     self::$encoder->startTag(SYNC_SETTINGS_SET);
00200                         self::$encoder->startTag(SYNC_SETTINGS_STATUS);
00201                         self::$encoder->content($oofSet->Status);
00202                         self::$encoder->endTag(); //SYNC_SETTINGS_STATUS
00203                     self::$encoder->endTag(); //SYNC_SETTINGS_SET
00204                 self::$encoder->endTag(); //SYNC_SETTINGS_OOF
00205             }
00206 
00207             //set device passwort
00208             if (isset($devicepassword)) {
00209                 self::$encoder->startTag(SYNC_SETTINGS_DEVICEPW);
00210                     self::$encoder->startTag(SYNC_SETTINGS_SET);
00211                         self::$encoder->startTag(SYNC_SETTINGS_STATUS);
00212                         self::$encoder->content($devicepassword->Status);
00213                         self::$encoder->endTag(); //SYNC_SETTINGS_STATUS
00214                     self::$encoder->endTag(); //SYNC_SETTINGS_SET
00215                 self::$encoder->endTag(); //SYNC_SETTINGS_DEVICEPW
00216             }
00217 
00218             //set device information
00219             if (isset($deviceinformation)) {
00220                 self::$encoder->startTag(SYNC_SETTINGS_DEVICEINFORMATION);
00221                     self::$encoder->startTag(SYNC_SETTINGS_SET);
00222                         self::$encoder->startTag(SYNC_SETTINGS_STATUS);
00223                         self::$encoder->content($deviceinformation->Status);
00224                         self::$encoder->endTag(); //SYNC_SETTINGS_STATUS
00225                     self::$encoder->endTag(); //SYNC_SETTINGS_SET
00226                 self::$encoder->endTag(); //SYNC_SETTINGS_DEVICEINFORMATION
00227             }
00228 
00229 
00230         self::$encoder->endTag(); //SYNC_SETTINGS_SETTINGS
00231 
00232         return true;
00233     }
00234 }
00235 ?>