Ejemplo n.º 1
0
 /**
  * Saves an user.
  *
  * If the request parameter "id" is null or 0, the function will add a new user,
  * if the "id" is an existing user, the function will update it.
  *
  * The save action will save some values into the setting table.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>                    id of the user to save.
  *  - mixed   <b>all other user fields</b> All the fields values to save.
  * </pre>
  *
  * If there is an error, the save will return a Zend_Controller_Action_Exception,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => Id of the user.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On error in the action save or wrong id.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $this->setCurrentProjectId();
     // Settings
     $setting = new Phprojekt_Setting();
     $setting->setModule('User');
     $message = $setting->validateSettings($this->getRequest()->getParams());
     if (!empty($message)) {
         $type = "error";
         $id = 0;
     } else {
         if (empty($id)) {
             $model = $this->getModelObject();
             $message = Phprojekt::getInstance()->translate(self::ADD_TRUE_TEXT);
         } else {
             $model = $this->getModelObject()->find($id);
             $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT);
         }
         $params = $this->setParams($this->getRequest()->getParams(), $model);
         Default_Helpers_Save::save($model, $params);
         if (empty($id)) {
             $id = $model->id;
         }
         $setting->setSettings($this->getRequest()->getParams(), $id);
         $type = "success";
     }
     $return = array('type' => $type, 'message' => $message, 'id' => $id);
     Phprojekt_Converter_Json::echoConvert($return);
 }
Ejemplo n.º 2
0
 /**
  * Do the save for the event
  * Add the full access to the owner and Read, Write and Delete access to the user involved
  *
  * @param array                     $request       Array with the POST data.
  * @param Calendar_Models_Calendar  $model         The model to save.
  * @param Phprojekt_Date_Collection $oneDate       Date object to save.
  * @param integer                   $daysDuration  How many days are between the start and end dates.
  * @param integer                   $participantId Id of the user to save the event.
  * @param integer                   $parentId      Id of the parent event.
  *
  * @return integer The parentId.
  */
 private function _saveEvent($request, $model, $oneDate, $daysDuration, $participantId, $parentId)
 {
     $request['startDatetime'] = date("Y-m-d", $oneDate) . ' ' . $request['startTime'];
     $request['endDatetime'] = date("Y-m-d", $oneDate + $daysDuration * 24 * 60 * 60) . ' ' . $request['endTime'];
     $request['participantId'] = $participantId;
     $request['parentId'] = $parentId;
     // The save is needed?
     if ($this->_needSave($model, $request)) {
         // Add 'read, write, downlaod and delete' access to the participant
         $request = Default_Helpers_Right::allowReadWriteDownloadDelete($request, $participantId);
         // Access for the owner
         if (null !== $model->ownerId) {
             $ownerId = $model->ownerId;
         } else {
             $ownerId = Phprojekt_Auth::getUserId();
         }
         // Set the status to "Pending" if there is any change and the event is for other user
         if ($participantId != $ownerId) {
             $request['status'] = 0;
         }
         $request = Default_Helpers_Right::allowAll($request, $ownerId);
         Default_Helpers_Save::save($model, $request);
     }
     if (null === $parentId) {
         $model->parentId = $model->id;
     }
     return $model->parentId;
 }
Ejemplo n.º 3
0
 /**
  * Saves the current minute item.
  *
  * If the request parameter "id" is null or 0, the function will add a new item,
  * if the "id" is an existing item, the function will update it.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>minutesId</b> The id of the minutes.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>                      id of the item to save.
  *  - mixed   <b>all other module fields</b> All the fields values to save.
  * </pre>
  *
  * If there is an error, the save will return a Phprojekt_PublishedException,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - code    => 0.
  *  - id      => Id of the minute item.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On error in the action save or wrong id.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $minutesId = (int) $this->getRequest()->getParam('minutesId');
     $this->setCurrentProjectId();
     $minutes = Phprojekt_Loader::getModel('Minutes', 'Minutes');
     $minutes->find($minutesId);
     if (empty($minutes->id)) {
         throw new Phprojekt_PublishedException(self::NOT_FOUND);
     } elseif (4 == $minutes->itemStatus) {
         throw new Phprojekt_PublishedException(self::MINUTES_READ_ONLY);
     } else {
         $id = (int) $this->getRequest()->getParam('id');
         if (empty($id)) {
             $model = Phprojekt_Loader::getModel('Minutes_SubModules_MinutesItem', 'MinutesItem')->init($minutesId);
             $message = Phprojekt::getInstance()->translate(self::ADD_TRUE_TEXT);
             $newItem = true;
         } else {
             $model = Phprojekt_Loader::getModel('Minutes_SubModules_MinutesItem', 'MinutesItem')->init($minutesId)->find($id);
             $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT);
             $newItem = false;
         }
         if ($model instanceof Phprojekt_Model_Interface) {
             $params = $this->setParams($this->getRequest()->getParams(), $minutes);
             Default_Helpers_Save::save($model, $params);
             $return = array('type' => 'success', 'message' => $message, 'code' => 0, 'id' => $model->id);
             Phprojekt_Converter_Json::echoConvert($return);
         } else {
             throw new Phprojekt_PublishedException(self::NOT_FOUND);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Save some fields for many items.
  * Only edit existing items.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - array <b>data</b> Array with itemId and field as index, and the value.
  *    ($data[2]['title'] = 'new tittle')
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - code    => 0.
  *  - id      => Comma separated ids of the items.
  * </pre>
  *
  * @return void
  */
 public function jsonSaveMultipleAction()
 {
     $data = (array) $this->getRequest()->getParam('data');
     $showId = array();
     $model = $this->getModelObject();
     $success = true;
     $this->setCurrentProjectId();
     foreach ($data as $id => $fields) {
         $model->find((int) $id);
         $params = $this->setParams($fields, $model);
         try {
             Default_Helpers_Save::save($model, $params);
             $showId[] = $id;
         } catch (Phprojekt_PublishedException $error) {
             $message = sprintf("ID %d. %s", $id, $error->getMessage());
             $success = false;
             $showId = array($id);
             break;
         }
     }
     if ($success) {
         $message = Phprojekt::getInstance()->translate(self::EDIT_MULTIPLE_TRUE_TEXT);
         $resultType = 'success';
     } else {
         $resultType = 'error';
     }
     $return = array('type' => $resultType, 'message' => $message, 'code' => 0, 'id' => implode(',', $showId));
     Phprojekt_Converter_Json::echoConvert($return);
 }
Ejemplo n.º 5
0
 /**
  * Save some fields for many projects.
  * Only edit existing projects.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - array <b>data</b> Array with projectId and field as index, and the value.
  *    ($data[2]['title'] = 'new tittle')
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - id      => Comma separated ids of the projects.
  * </pre>
  *
  * @return void
  */
 public function jsonSaveMultipleAction()
 {
     $data = (array) $this->getRequest()->getParam('data');
     $showId = array();
     $model = $this->getModelObject();
     $success = true;
     $this->setCurrentProjectId();
     foreach ($data as $id => $fields) {
         $model->find($id);
         $node = new Phprojekt_Tree_Node_Database($model, $id);
         try {
             $nodeId = (int) $this->getRequest()->getParam('nodeId', null);
             $newNode = Default_Helpers_Save::save($node, $fields, $nodeId);
             $showId[] = $newNode->id;
         } catch (Zend_Controller_Action_Exception $error) {
             $success = false;
             $showId = array($id);
             $message = sprintf("ID %d. %s", $id, $error->getMessage());
             break;
         }
     }
     if ($success) {
         $message = Phprojekt::getInstance()->translate(self::EDIT_MULTIPLE_TRUE_TEXT);
         $resultType = 'success';
     } else {
         $resultType = 'error';
     }
     $return = array('type' => $resultType, 'message' => $message, 'id' => implode(',', $showId));
     Phprojekt_Converter_Json::echoConvert($return);
 }
Ejemplo n.º 6
0
 /**
  * Saves the current minute item.
  *
  * If the request parameter "id" is null or 0, the function will add a new item,
  * if the "id" is an existing item, the function will update it.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>minutesId</b> The id of the minutes.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>                      id of the item to save.
  *  - mixed   <b>all other module fields</b> All the fields values to save.
  * </pre>
  *
  * If there is an error, the save will return a Zend_Controller_Action_Exception,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => Id of the minute item.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On error in the action save or wrong id.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $this->setCurrentProjectId();
     $model = $this->getModelObject();
     if (empty($model->getParent()->id)) {
         throw new Zend_Controller_Action_Exception(self::NOT_FOUND, 404);
     } elseif (4 == $model->getParent()->itemStatus) {
         throw new Zend_Controller_Action_Exception(self::MINUTES_READ_ONLY, 403);
     } else {
         $id = (int) $this->getRequest()->getParam('id');
         if (empty($id)) {
             $message = Phprojekt::getInstance()->translate(self::ADD_TRUE_TEXT);
         } else {
             $model->find($id);
             $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT);
         }
         if ($model instanceof Phprojekt_Model_Interface) {
             $params = $this->setParams($this->getRequest()->getParams(), $model->getParent());
             Default_Helpers_Save::save($model, $params);
             $return = array('type' => 'success', 'message' => $message, 'id' => $model->id);
             Phprojekt_Converter_Json::echoConvert($return);
         } else {
             throw new Zend_Controller_Action_Exception(self::NOT_FOUND, 404);
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * Saves a booking.
  *
  * If the request parameter "id" is null or 0, the function will add a new booking,
  * if the "id" is an existing booking, the function will update it.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>                      id of the booking to save.
  *  - mixed   <b>all other module fields</b> All the fields values to save.
  * </pre>
  *
  * If there is an error, the save will return a Zend_Controller_Action_Exception,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => Id of the booking.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On error in the action save or wrong id.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $this->setCurrentProjectId();
     if (empty($id)) {
         $model = $this->getModelObject();
         $message = Phprojekt::getInstance()->translate(self::ADD_TRUE_TEXT);
     } else {
         $model = $this->getModelObject()->find($id);
         $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT);
     }
     $params = $this->setParams($this->getRequest()->getParams(), $model);
     Default_Helpers_Save::save($model, $params);
     $return = array('type' => 'success', 'message' => $message, 'id' => $model->id);
     Phprojekt_Converter_Json::echoConvert($return);
 }
Ejemplo n.º 8
0
 /**
  * This function is used only for integration purposes and should only
  * be called when integrating the user data!
  *
  **/
 private static function _saveUser($params)
 {
     $moduleName = "Phprojekt_User_User";
     if (Phprojekt_Loader::tryToLoadLibClass($moduleName)) {
         // Temporarily login as admin user
         // This is only to get rights to add user
         // Ugly hack but PHProjekt backend has not thought of this situation
         $authNamespace = new Zend_Session_Namespace('Phprojekt_Auth-login');
         $authNamespace->userId = 1;
         $authNamespace->admin = true;
         $exc = null;
         try {
             $db = Phprojekt::getInstance()->getDb();
             $model = new $moduleName($db);
             if ($params['id'] > 0) {
                 $model = $model->find($params['id']);
             }
             Default_Helpers_Save::save($model, $params);
             $setting = new Phprojekt_Setting();
             $setting->setModule('User');
             $setting->setSettings($params, $model->id);
         } catch (Exception $e) {
             $exc = $e;
         }
         // Set user not logged in
         unset($authNamespace->userId);
         unset($authNamespace->admin);
         if ($exc instanceof Exception) {
             // Throw exception if user creation failed
             throw $exc;
         }
         return true;
     }
     return false;
 }