/**
  * Returns all the modules and the access for one roleId.
  *
  * Returns a list of all the modules with:
  * <pre>
  *  - id       => id of the module.
  *  - name     => Name of the module.
  *  - label    => Display for the module.
  *  - none     => True or false for none access.
  *  - read     => True or false for read access.
  *  - write    => True or false for write access.
  *  - access   => True or false for access access.
  *  - create   => True or false for create access.
  *  - copy     => True or false for copy access.
  *  - delete   => True or false for delete access.
  *  - download => True or false for download access.
  *  - admin    => True or false for admin access.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b> The role id for consult.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetModulesAccessAction()
 {
     $role = new Phprojekt_Role_RoleModulePermissions();
     $roleId = (int) $this->getRequest()->getParam('id', null);
     $modules = $role->getRoleModulePermissionsById($roleId);
     Phprojekt_Converter_Json::echoConvert($modules);
 }
 /**
  * Search for words.
  *
  * Returns a list of items that have the word, sorted by module with:
  * <pre>
  *  - id            => id of the item found.
  *  - moduleId      => id of the module.
  *  - moduleName    => Name of the module.
  *  - moduleLabel   => Display for the module.
  *  - firstDisplay  => Firts display for the item (Ej. title).
  *  - secondDisplay => Second display for the item (Ej. notes).
  *  - projectId     => Parent project id of the item.
  * </pre>
  *
  * REQUIRES request parameters:
  * <pre>
  *  - string <b>words</b> An string of words (Will be separated by the spaces).
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>count</b> Number of results.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonSearchAction()
 {
     $words = (string) $this->getRequest()->getParam('words');
     $count = (int) $this->getRequest()->getParam('count', null);
     $offset = (int) $this->getRequest()->getParam('start', null);
     $search = Phprojekt_Loader::getLibraryClass('Phprojekt_Search');
     $results = $search->search($words, $count);
     Phprojekt_Converter_Json::echoConvert($results);
 }
 /**
  * Search for words.
  *
  * Returns a list of items that have the word, sorted by module with:
  * <pre>
  *  - id            => id of the item found.
  *  - moduleId      => id of the module.
  *  - moduleName    => Name of the module.
  *  - moduleLabel   => Display for the module.
  *  - firstDisplay  => Firts display for the item (Ej. title).
  *  - secondDisplay => Second display for the item (Ej. notes).
  *  - projectId     => Parent project id of the item.
  * </pre>
  *
  * REQUIRES request parameters:
  * <pre>
  *  - string <b>words</b> An string of words (Will be separated by the spaces).
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>count</b> Number of results.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonSearchAction()
 {
     $words = (string) $this->getRequest()->getParam('words');
     $count = (int) $this->getRequest()->getParam('count', null);
     $offset = (int) $this->getRequest()->getParam('start', null);
     $search = new Phprojekt_Search();
     $tags = new Phprojekt_Tags();
     $searchresults = $search->search($words, $count);
     $tagresults = $tags->search($words, $count);
     $results = array('search' => $searchresults, 'tags' => $tagresults);
     Phprojekt_Converter_Json::echoConvert($results);
 }
Beispiel #4
0
 /**
  * Test json convertion of single value
  */
 public function testConvertValue()
 {
     $data = 'This is a test of convetion';
     $converted = '{}&&("This is a test of convetion")';
     $result = Phprojekt_Converter_Json::convert($data);
     $this->assertEquals($converted, $result);
     $data = array('This is a test of convetion');
     $converted = '{}&&(["This is a test of convetion"])';
     $result = Phprojekt_Converter_Json::convert($data);
     $this->assertEquals($converted, $result);
     $result = Phprojekt_Converter_Json::convert(array());
     $converted = '{}&&({"metadata":[]})';
     $this->assertEquals($converted, $result);
 }
 /**
  * Returns the statistics data.
  *
  * The return have
  * <pre>
  *  - users    => id and display of all the users involved
  *  - projects => id and display of all the projects involved.
  *  - rows     => pair projectId => userId - Booked minutes.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - date    <b>startDate</b> ISO start date for filter.
  *  - date    <b>endDate</b>   ISO end date for filter.
  *  - integer <b>nodeId</b>    List all the projects under nodeId.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @throws Zend_Controller_Action_Exception On error in the parameters.
  *
  * @return void
  */
 public function jsonGetStatisticAction()
 {
     $startDate = Cleaner::sanitize('date', $this->getRequest()->getParam('startDate', date("Y-m-d")));
     $endDate = Cleaner::sanitize('date', $this->getRequest()->getParam('endDate', date("Y-m-d")));
     $projectId = (int) $this->getRequest()->getParam('nodeId', null);
     if ($startDate <= $endDate) {
         $data = $this->getModelObject()->getStatistics($startDate, $endDate, $projectId);
         Phprojekt_Converter_Json::echoConvert($data);
     } else {
         $messageTitle = Phprojekt::getInstance()->translate('Period');
         $messageDesc = Phprojekt::getInstance()->translate('End time can not be before Start time');
         throw new Zend_Controller_Action_Exception($messageTitle . ': ' . $messageDesc, 400);
     }
 }
 /**
  * When requesting the default values, adjust the start date to the start
  * date of the project.
  */
 public function jsonDetailAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     if (!empty($id)) {
         parent::jsonDetailAction();
     } else {
         $this->setCurrentProjectId();
         $project = new Project_Models_Project();
         $project->find(Phprojekt::getCurrentProjectId());
         $record = new Todo_Models_Todo();
         $record->startDate = $project->startDate;
         $record->endDate = $project->endDate;
         Phprojekt_Converter_Json::echoConvert($record, Phprojekt_ModelInformation_Default::ORDERING_FORM);
     }
 }
Beispiel #7
0
 /**
  * Returns the detail (fields and data) of one item from the model.
  *
  * The return have:
  *  - The metadata of each field.
  *  - The data of one item.
  *  - The number of rows.
  *
  * If the request parameter "id" is null or 0, the data will be all values of a "new item",
  * if the "id" is an existing item, the data will be all the values of the item.
  *
  * For new items, the author and date values are set.
  *
  * The function use Phprojekt_ModelInformation_Default::ORDERING_FORM for get and sort the fields.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item to consult.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonDetailAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $this->setCurrentProjectId();
     if (empty($id)) {
         // New item - Adds the author and the date of creation
         $record = $this->getModelObject();
         $record->author = Phprojekt_Auth::getUserId();
         $record->date = date("Y-m-d");
     } else {
         $record = $this->getModelObject()->find($id);
         if ($record->solvedBy == 0) {
             // This is because of the solved date being unable to be deleted from the item
             $record->solvedDate = '';
         }
     }
     Phprojekt_Converter_Json::echoConvert($record, Phprojekt_ModelInformation_Default::ORDERING_FORM);
 }
 /**
  * Returns the list of actions done in one item.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>moduleId</b> id of the module (if moduleName is sent, this is not necessary).
  *  - integer <b>itemId</b>   id of the item.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>userId</b>     To filter by user id.
  *  - string  <b>moduleName</b> Name of the module (if moduleId is sent, this is not necessary).
  *  - date    <b>startDate</b>  To filter by start date.
  *  - date    <b>endDate</b>    To filter by end date.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @throws Zend_Controller_Action_Exception On missing or wrong moduleId or itemId.
  *
  * @return void
  */
 public function jsonListAction()
 {
     $moduleId = (int) $this->getRequest()->getParam('moduleId', null);
     $itemId = (int) $this->getRequest()->getParam('itemId', null);
     $userId = (int) $this->getRequest()->getParam('userId', null);
     $moduleName = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', 'Default'));
     $startDate = Cleaner::sanitize('date', $this->getRequest()->getParam('startDate', null));
     $endDate = Cleaner::sanitize('date', $this->getRequest()->getParam('endDate', null));
     $this->setCurrentProjectId();
     if (empty($moduleId)) {
         $moduleId = Phprojekt_Module::getId($moduleName);
     }
     if (empty($itemId) || empty($moduleId)) {
         throw new Zend_Controller_Action_Exception("Invalid module or item", 400);
     } else {
         $history = new Phprojekt_History();
         $data = $history->getHistoryData(null, $itemId, $moduleId, $startDate, $endDate, $userId);
         $data = array('data' => $data);
         Phprojekt_Converter_Json::echoConvert($data);
     }
 }
 /**
  * Saves the design of all the fields in the module.
  *
  * If the request parameter "id" is null or 0, the function will add a new module,
  * if the "id" is an existing module, the function will update it.
  *
  * The save action will try to add or update the module table itself and the database_manager.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b>           id of the module to save.
  *  - string  <b>designerData</b> Data of the fields.
  *  - string  <b>name</b>         Name of the module.
  *  - string  <b>label</b>        Display of the module.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - id      => id of the module.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On error in the action save.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $data = $this->getRequest()->getParam('designerData');
     $saveType = (int) $this->getRequest()->getParam('saveType');
     $model = null;
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('name', null));
     $this->setCurrentProjectId();
     if (empty($module)) {
         $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('label'));
     }
     $module = ucfirst(str_replace(" ", "", $module));
     $this->getRequest()->setParam('name', $module);
     if ($id > 0) {
         $model = Phprojekt_Loader::getModel($module, $module);
     }
     $message = $this->_handleDatabaseChange($model, $module, $data, $saveType, $id);
     if (!is_null($message)) {
         Phprojekt_Converter_Json::echoConvert($message);
         return;
     }
     $this->setCurrentProjectId();
     $message = '';
     if (empty($id)) {
         $model = new Phprojekt_Module_Module();
         $message = Phprojekt::getInstance()->translate('The module was added correctly');
     } else {
         $model = new Phprojekt_Module_Module();
         $model = $model->find($id);
         $message = Phprojekt::getInstance()->translate('The module was edited correctly');
     }
     $model->saveModule($this->getRequest()->getParams());
     Phprojekt_Module::clearCache();
     $return = array('type' => 'success', 'message' => $message, 'id' => $model->id);
     Phprojekt_Converter_Json::echoConvert($return);
 }
 /**
  * Perform the upgrade for a single module.
  *
  * The module is taken from the 'upgradeModule' parameter of the request.
  *
  * @return void
  */
 public function jsonUpgradeAction()
 {
     if (!Phprojekt_Auth::isAdminUser()) {
         throw new Zend_Controller_Action_Exception('Insufficient rights.', 403);
     }
     $extensions = new Phprojekt_Extensions(PHPR_CORE_PATH);
     $migration = new Phprojekt_Migration($extensions);
     $failed = true;
     try {
         $migration->performUpgrade($this->getRequest()->getParam('upgradeModule'));
         $failed = false;
     } catch (Phprojekt_Migration_IKilledTheDatabaseException $e) {
         Phprojekt::getInstance()->getLog()->debug("IKilledTheDatabaseException occurred while migrating: " . $e->getFile() . ':' . $e->getLine() . "\n" . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n");
         Phprojekt_Converter_Json::echoConvert(array('type' => 'fatalFailure', 'message' => 'A fatal error has occured.'));
     } catch (Exception $e) {
         Phprojekt::getInstance()->getLog()->debug("Exception occurred while migrating: " . $e->getFile() . ':' . $e->getLine() . "\n" . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n");
         Phprojekt_Converter_Json::echoConvert(array('type' => 'failure', 'message' => 'An error has occured.'));
     }
     if (!$failed) {
         Phprojekt_Converter_Json::echoConvert(array('type' => 'success', 'message' => 'The module was upgraded correctly'));
     }
 }
Beispiel #11
0
 /**
  * Sends a mail containing the Minutes protocol.
  *
  * A pdf can be also attached to the mail.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the minute to send.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - array <b>options</b> If contain 'pdf', a pdf is attached to the mail.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - code    => 0 for success, -1 for error.
  *  - id      => id of the minute.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On error in the send action or wrong id.
  *
  * @return void
  */
 public function jsonSendMailAction()
 {
     $errors = array();
     $params = $this->getRequest()->getParams();
     $this->setCurrentProjectId();
     // Sanity check
     if (empty($params['id']) || !is_numeric($params['id'])) {
         throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
     }
     $minutesId = (int) $params['id'];
     $minutes = $this->getModelObject()->find($minutesId);
     // Was the id provided a valid one?
     if (!$minutes instanceof Phprojekt_Model_Interface || !$minutes->id) {
         // Invalid ID
         throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
     }
     // Security check: is the current user owner of this minutes entry?
     if ($minutes->ownerId != PHprojekt_Auth::getUserId()) {
         throw new Phprojekt_PublishedException(self::USER_IS_NOT_OWNER);
     }
     $mail = new Phprojekt_Mail();
     /* @var $mail Zend_Mail */
     $smtpTransport = $mail->setTransport();
     $validator = new Zend_Validate_EmailAddress();
     $emailsListed = $this->getRequest()->getParam('recipients', array());
     $emailsListed = $this->_getMailFromUserIds($emailsListed, $validator);
     $emailsWritten = $this->getRequest()->getParam('additional', '');
     $emailsWritten = $this->_getMailFromCsvString($emailsWritten, $validator);
     $userMails = array_merge($emailsListed, $emailsWritten);
     $errors = $this->_addRecipients($mail, $userMails, $errors);
     // Sanity check
     if (array() === $mail->getRecipients()) {
         $errors[] = array('message' => self::MISSING_MAIL_RECIPIENTS, 'value' => null);
     }
     if (!count($errors)) {
         // Handle PDF attachment if needed
         if (!empty($params['options']) && is_array($params['options'])) {
             if (in_array('pdf', $params['options'])) {
                 $pdf = (string) Minutes_Helpers_Pdf::getPdf($minutes);
                 $mail->createAttachment($pdf, 'application/x-pdf', Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_8BIT, 'minutes_' . $minutesId . '.pdf');
             }
         }
         // Set sender address
         $ownerModel = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
         $ownerModel->find($minutes->ownerId);
         $ownerEmail = $ownerModel->getSetting('email');
         $display = $ownerModel->getDisplay();
         $mail->setFrom($ownerEmail, $ownerModel->applyDisplay($display, $ownerModel));
         // Set subject
         $subject = sprintf('%s "%s", %s', Phprojekt::getInstance()->translate('Meeting minutes for'), $minutes->title, $minutes->meetingDatetime);
         $mail->setSubject($subject);
         // Set mail content
         $mail->setBodyText($subject, 'utf-8');
         $mail->setBodyHtml($this->_getHtmlList($minutes), 'utf-8');
         // Keep send() commented out until test phase is over
         $mail->send($smtpTransport);
         $return = array('type' => 'success', 'message' => Phprojekt::getInstance()->translate(self::MAIL_SUCCESS_TEXT), 'code' => 0, 'id' => $minutesId);
     } else {
         $message = Phprojekt::getInstance()->translate(self::MAIL_FAIL_TEXT);
         foreach ($errors as $error) {
             $message .= "\n";
             $message .= sprintf("%s %s", Phprojekt::getInstance()->translate($error['message']), $error['value']);
         }
         $return = array('type' => 'error', 'message' => nl2br($message), 'code' => -1, 'id' => $minutesId);
     }
     Phprojekt_Converter_Json::echoConvert($return);
 }
Beispiel #12
0
 /**
  * Test json convertion of tags
  */
 public function testConvertTags()
 {
     $tagObj = Phprojekt_Tags::getInstance();
     $tags = $tagObj->getTags(1);
     $fields = $tagObj->getFieldDefinition();
     $result = Phprojekt_Converter_Json::convert($tags, $fields);
     $converted = '{}&&({"metadata":[{"key":"string","label":"Tag"},{"key":"count","label":"Count"}],"data":[{"';
     $this->assertEquals($converted, substr($result, 0, strlen($converted)));
 }
 /**
  * Deletes a module.
  *
  * Deletes the module entries, the module itself,
  * the databasemanager entry and the table itself.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item to delete.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => id of the deleted item.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On missing or wrong id, or on error in the action delete.
  *
  * @return void
  */
 public function jsonDeleteAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     if (empty($id)) {
         throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400);
     }
     $model = $this->getModelObject()->find($id);
     if ($model instanceof Phprojekt_ActiveRecord_Abstract) {
         if (is_dir(PHPR_CORE_PATH . $model->name)) {
             throw new Zend_Controller_Action_Exception(self::CAN_NOT_DELETE_SYSTEM_MODULE, 422);
         }
         $databaseModel = Phprojekt_Loader::getModel($model->name, $model->name);
         if ($databaseModel instanceof Phprojekt_Item_Abstract) {
             $databaseManager = new Phprojekt_DatabaseManager($databaseModel);
             if (Default_Helpers_Delete::delete($model)) {
                 $return = $databaseManager->deleteModule();
             } else {
                 $return = false;
             }
         } else {
             $return = Default_Helpers_Delete::delete($model);
         }
         if ($return === false) {
             $message = Phprojekt::getInstance()->translate('The module can not be deleted');
             $type = 'error';
         } else {
             Phprojekt::removeControllersFolders();
             $message = Phprojekt::getInstance()->translate('The module was deleted correctly');
             $type = 'success';
         }
         $return = array('type' => $type, 'message' => $message, 'id' => $id);
         Phprojekt_Converter_Json::echoConvert($return);
     } else {
         throw new Zend_Controller_Action_Exception(self::NOT_FOUND, 404);
     }
 }
Beispiel #14
0
 /**
  * Returns the rights for all the users of one item.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>     The id of the item to consult.
  *  - integer <b>nodeId</b> The id of the parent project.
  * </pre>
  *
  * The return is an array like ('#userID' => {'admin': true/false, 'read': true/false, etc})
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetUsersRightsAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $projectId = (int) $this->getRequest()->getParam('nodeId');
     if (empty($id)) {
         if (empty($projectId)) {
             $record = $this->getModelObject();
         } else {
             $model = Phprojekt_Loader::getModel('Project', 'Project');
             $record = $model->find($projectId);
         }
     } else {
         $record = $this->getModelObject()->find($id);
     }
     if ($record instanceof Phprojekt_Model_Interface) {
         Phprojekt_Converter_Json::echoConvert($record->getUsersRights());
     } else {
         Phprojekt_Converter_Json::echoConvert(array());
     }
 }
 /**
  * Saves the design of all the fields in the module.
  *
  * If the request parameter "id" is null or 0, the function will add a new module,
  * if the "id" is an existing module, the function will update it.
  *
  * The save action will try to add or update the module table itself and the database_manager.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b>           id of the module to save.
  *  - string  <b>designerData</b> Data of the fields.
  *  - string  <b>name</b>         Name of the module.
  *  - string  <b>label</b>        Display of the module.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - code    => 0.
  *  - id      => id of the module.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On error in the action save.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     $data = $this->getRequest()->getParam('designerData');
     $saveType = (int) $this->getRequest()->getParam('saveType');
     $model = null;
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('name', null));
     $this->setCurrentProjectId();
     if (empty($module)) {
         $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('label'));
     }
     $module = ucfirst(str_replace(" ", "", $module));
     if ($id > 0) {
         $model = Phprojekt_Loader::getModel($module, $module);
     }
     if ($model instanceof Phprojekt_Item_Abstract || $id == 0) {
         $databaseManager = new Phprojekt_DatabaseManager($model);
         $data = Zend_Json_Decoder::decode($data);
         // Validate
         if ($databaseManager->recordValidate($data, $saveType)) {
             // Update Table Structure
             $tableData = $this->_getTableData($data);
             if (!$databaseManager->syncTable($data, $module, $tableData)) {
                 $type = 'error';
                 $message = Phprojekt::getInstance()->translate('There was an error writing the table');
             } else {
                 // Update DatabaseManager Table
                 $databaseManager->saveData($module, $data, $tableData);
                 if (empty($id)) {
                     $message = Phprojekt::getInstance()->translate('The table module was created correctly');
                 } else {
                     $message = Phprojekt::getInstance()->translate('The table module was edited correctly');
                 }
                 $type = 'success';
             }
         } else {
             $error = $databaseManager->getError();
             $message = $error['label'] . ': ' . $error['message'];
             $type = 'error';
         }
     } else {
         $type = 'success';
         $message = null;
     }
     $return = array('type' => $type, 'message' => $message, 'code' => 0, 'id' => $id);
     Phprojekt_Converter_Json::echoConvert($return);
 }
 /**
  * Save the favorites projects for the current user.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - array <b>favorites</b> Array with ids of the projects.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => 0.
  * </pre>
  *
  * @return void
  */
 public function jsonFavoritesSaveAction()
 {
     $setting = new Phprojekt_Setting();
     $setting->setModule('Timecard');
     $setting->setSettings($this->getRequest()->getParams());
     $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT);
     $return = array('type' => 'success', 'message' => $message, 'id' => 0);
     Phprojekt_Converter_Json::echoConvert($return);
 }
Beispiel #17
0
 /**
  * Deletes a module.
  *
  * Deletes the module entries, the module itself,
  * the databasemanager entry and the table itself.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item to delete.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - code    => 0.
  *  - id      => id of the deleted item.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On missing or wrong id, or on error in the action delete.
  *
  * @return void
  */
 public function jsonDeleteAction()
 {
     $id = (int) $this->getRequest()->getParam('id');
     if (empty($id)) {
         throw new Phprojekt_PublishedException(self::ID_REQUIRED_TEXT);
     }
     $model = $this->getModelObject()->find($id);
     if ($model instanceof Phprojekt_Model_Interface) {
         $databaseModel = Phprojekt_Loader::getModel($model->name, $model->name);
         $databaseManager = new Phprojekt_DatabaseManager($databaseModel);
         if (Default_Helpers_Delete::delete($model) === false || $databaseManager->deleteModule() === false) {
             $message = Phprojekt::getInstance()->translate('The module can not be deleted');
         } else {
             $message = Phprojekt::getInstance()->translate('The module was deleted correctly');
         }
         $return = array('type' => 'success', 'message' => $message, 'code' => 0, 'id' => $id);
         Phprojekt_Converter_Json::echoConvert($return);
     } else {
         throw new Phprojekt_PublishedException(self::NOT_FOUND);
     }
 }
Beispiel #18
0
 /**
  * Returns a specific list of users.
  *
  * Returns a list of all the selected users with:
  * <pre>
  *  - id      => id of user.
  *  - display => Display for the user.
  * </pre>
  *
  * REQUIRES request parameters:
  * <pre>
  *  - string <b>users</b> Comma separated ids of the users.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetSpecificUsersAction()
 {
     $ids = Cleaner::sanitize('arrayofint', $this->getRequest()->getParam('users', array()));
     if (empty($ids)) {
         $ids[] = (int) PHprojekt_Auth::getUserId();
     }
     $db = Phprojekt::getInstance()->getDb();
     $where = sprintf('status = %s AND id IN (%s)', $db->quote('A'), implode(", ", $ids));
     $user = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
     $display = $user->getDisplay();
     $records = $user->fetchAll($where, $display);
     $data = array();
     foreach ($records as $record) {
         $data['data'][] = array('id' => (int) $record->id, 'display' => $record->applyDisplay($display, $record));
     }
     Phprojekt_Converter_Json::echoConvert($data, Phprojekt_ModelInformation_Default::ORDERING_LIST);
 }
 /**
  * Return ical busy times for the given time period and user. If no
  * user is given, default to the currently logged in user.
  *
  * Request parameters:
  *  int         user    => The id of the user. May be null.
  *  datetime    start   => The start of the period to check.
  *  datetime    end     => The end of the period to check.
  *
  * Response
  *  Array of {
  *      datetime start => The start of the busy period.
  *      datetime end   => The end of the busy period.
  *  }
  */
 public function jsonBusyTimesAction()
 {
     $user = $this->getRequest()->getParam('user', Phprojekt_Auth_Proxy::getEffectiveUserId());
     $start = $this->getRequest()->getParam('start');
     $end = $this->getRequest()->getParam('end');
     if (!Cleaner::validate('int', $user)) {
         throw new Zend_Controller_Action_Exception("Invalid id '{$id}'", 400);
     }
     $user = (int) $user;
     if (!self::_validateTimestamp($start)) {
         throw new Zend_Controller_Action_Exception("Invalid start timestamp '{$start}'", 400);
     }
     if (!self::_validateTimestamp($end)) {
         throw new Zend_Controller_Action_Exception("Invalid end timestamp '{$start}'", 400);
     }
     $start = new Datetime($start, Phprojekt_User_User::getUserDateTimeZone());
     $end = new Datetime($end, Phprojekt_User_User::getUserDateTimeZone());
     $model = new Calendar2_Models_Calendar2();
     $events = $model->fetchAllForPeriod($start, $end);
     $busyPeriods = array();
     foreach ($events as $event) {
         $busyPeriods[] = array('start' => new Datetime($event->start, new DateTimeZone('UTC')), 'end' => new Datetime($event->end, new DateTimeZone('UTC')));
     }
     Phprojekt_Converter_Json::echoConvert(Calendar2_Helper_Time::compactPeriods($busyPeriods));
 }
Beispiel #20
0
 /**
  * Saves the new values of the projects dates.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - array <b>projects</b> Array with projectId,startDate and endDate by comma separated
  * </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      => 0.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On error in the action save or wrong parameters.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $projects = (array) $this->getRequest()->getParam('projects', array());
     $activeRecord = Phprojekt_Loader::getModel('Project', 'Project');
     $rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
     $userId = Phprojekt_Auth::getUserId();
     $this->setCurrentProjectId();
     // Error check: no project received
     if (empty($projects)) {
         $label = Phprojekt::getInstance()->translate('Projects');
         $message = Phprojekt::getInstance()->translate('No project info was received');
         throw new Phprojekt_PublishedException($label . ': ' . $message);
     }
     foreach ($projects as $project) {
         list($id, $startDate, $endDate) = explode(",", $project);
         // Check: are the three values available?
         if (empty($id) || empty($startDate) || empty($endDate)) {
             $label = Phprojekt::getInstance()->translate('Projects');
             $message = Phprojekt::getInstance()->translate('Incomplete data received');
             throw new Phprojekt_PublishedException($label . ': ' . $message);
         }
         $id = (int) $id;
         $activeRecord->find($id);
         // Check: project id exists?
         if (empty($activeRecord->id)) {
             $label = Phprojekt::getInstance()->translate('Project');
             $message = Phprojekt::getInstance()->translate('Id not found #') . $id;
             throw new Phprojekt_PublishedException($label . ': ' . $message);
         }
         // Check: dates are valid?
         $validStart = Cleaner::validate('date', $startDate, false);
         $validEnd = Cleaner::validate('date', $endDate, false);
         if (!$validStart || !$validEnd) {
             $label = Phprojekt::getInstance()->translate('Project id #') . $id;
             if (!$validStart) {
                 $message = Phprojekt::getInstance()->translate('Start date invalid');
             } else {
                 $message = Phprojekt::getInstance()->translate('End date invalid');
             }
             throw new Phprojekt_PublishedException($label . ': ' . $message);
         }
         // Check: start date after end date?
         $startDateTemp = strtotime($startDate);
         $endDateTemp = strtotime($endDate);
         if ($startDateTemp > $endDateTemp) {
             $label = Phprojekt::getInstance()->translate('Project id #') . $id;
             $message = Phprojekt::getInstance()->translate('Start date can not be after End date');
             throw new Phprojekt_PublishedException($label . ': ' . $message);
         }
         $activeRecord->startDate = $startDate;
         $activeRecord->endDate = $endDate;
         if ($rights->getItemRight(1, $id, $userId) >= Phprojekt_Acl::WRITE) {
             $activeRecord->parentSave();
         }
     }
     $message = Phprojekt::getInstance()->translate(self::EDIT_MULTIPLE_TRUE_TEXT);
     $return = array('type' => 'success', 'message' => $message, 'code' => 0, 'id' => 0);
     Phprojekt_Converter_Json::echoConvert($return);
 }
 /**
  * Sets the tutorialDisplayed setting of the current user.
  *
  * Sets the tutorialDisplayed setting of the current user, indicating that the tutorial has been displayed.
  * The request parameter "displayed" should either be true or false.
  *
  * @return void
  */
 public function jsonSetTutorialDisplayedAction()
 {
     $displayed = $this->getRequest()->getParam('displayed', "");
     if ($displayed == "true") {
         $displayed = "true";
     } else {
         $displayed = "false";
     }
     $user = Phprojekt_Auth_Proxy::getEffectiveUser();
     $settings = $user->settings->fetchAll();
     $found = false;
     foreach ($settings as $setting) {
         // Update
         if ($setting->keyValue == "tutorialDisplayed") {
             $setting->value = $displayed;
             $setting->save();
             $found = true;
             break;
         }
     }
     if (!$found) {
         // Create
         $record = $user->settings->create();
         $record->moduleId = 0;
         $record->keyValue = "tutorialDisplayed";
         $record->value = $displayed;
         $record->identifier = 'Core';
         $record->save();
     }
     Phprojekt_Converter_Json::echoConvert(array());
 }
Beispiel #22
0
 /**
  * Returns a list of items for sort ordering.
  *
  * The return data have:
  * <pre>
  *  - id:   Order number.
  *  - name: Title of the item.
  * </pre>
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>minutesId</b> The id of the minutes.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonListItemSortOrderAction()
 {
     $minutesId = (int) $this->getRequest()->getParam('minutesId');
     $items = Phprojekt_Loader::getModel('Minutes_SubModules_MinutesItem', 'MinutesItem')->init($minutesId)->fetchAll();
     $return = array('data' => array(array('id' => 0, 'name' => '')));
     foreach ($items as $item) {
         $return['data'][] = array('id' => (int) $item->sortOrder, 'name' => $item->title);
     }
     Phprojekt_Converter_Json::echoConvert($return);
 }
Beispiel #23
0
 /**
  * Executes the login by json using the username and password.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - string <b>username</b> Username for login.
  *  - string <b>password</b> Password for login.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  * </pre>
  *
  * @return void
  */
 public function jsonLoginAction()
 {
     $username = Cleaner::sanitize('xss', $this->getRequest()->getParam('username', null));
     $password = Cleaner::sanitize('xss', $this->getRequest()->getParam('password', null));
     try {
         $success = Phprojekt_Auth::login($username, $password);
         if ($success === true) {
             $return = array('type' => 'success', 'message' => '');
         }
     } catch (Phprojekt_Auth_Exception $error) {
         $return = array('type' => 'error', 'message' => $error->getMessage());
     }
     $this->_helper->viewRenderer->setNoRender();
     $this->view->clearVars();
     Phprojekt_Converter_Json::echoConvert($return);
 }
 /**
  * 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);
 }
 /**
  * Returns a list of items for sort ordering.
  *
  * The return data have:
  * <pre>
  *  - id:   Order number.
  *  - name: Title of the item.
  * </pre>
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>minutesId</b> The id of the minutes.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonListItemSortOrderAction()
 {
     $minutesId = (int) $this->getRequest()->getParam('minutesId', 0);
     $where = sprintf('minutes_id = %d', (int) $minutesId);
     $items = $this->getModelObject()->fetchAll($where);
     $return = array('data' => array(array('id' => 0, 'name' => '')));
     foreach ($items as $item) {
         $return['data'][] = array('id' => (int) $item->sortOrder, 'name' => $item->title);
     }
     Phprojekt_Converter_Json::echoConvert($return);
 }
 /**
  * Delete the tags for one item.
  *
  * REQUIRES request parameters:
  * <pre>
  *  - integer <b>id</b> id of the item.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - string <b>moduleName</b> Name of the module.
  * </pre>
  *
  * If there is an error, the delete will return a Zend_Controller_Action_Exception,
  * if not, it returns a string in JSON format with:
  * <pre>
  *  - type    => 'success'.
  *  - message => Success message.
  *  - id      => 0.
  * </pre>
  *
  * @throws Zend_Controller_Action_Exception On missing or wrong id.
  *
  * @return void
  */
 public function jsonDeleteTagsAction()
 {
     $tagObj = new Phprojekt_Tags();
     $id = (int) $this->getRequest()->getParam('id');
     if (empty($id)) {
         throw new Zend_Controller_Action_Exception(self::ID_REQUIRED_TEXT, 400);
     }
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', 'Project'));
     $moduleId = (int) Phprojekt_Module::getId($module);
     $tagObj->deleteTagsByItem($moduleId, $id);
     $message = Phprojekt::getInstance()->translate('The Tags were deleted correctly');
     $return = array('type' => 'success', 'message' => $message, 'id' => 0);
     Phprojekt_Converter_Json::echoConvert($return);
 }
 /**
  * Returns all the role-user relation with the project.
  *
  * Returns a list of all the roles related to the users under the project with:
  * <pre>
  *  - id    => id of the role.
  *  - name  => Name of the role.
  *  - users => id and display of the users with the role.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b>     The project id for consult.
  *  - integer <b>nodeId</b> The id of the parent project.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetProjectRoleUserRelationAction()
 {
     $projectId = (int) $this->getRequest()->getParam('id');
     $parentId = (int) $this->getRequest()->getParam('nodeId');
     // On new entries, get the parent data
     if (empty($projectId)) {
         $projectId = $parentId;
     }
     $project = new Project_Models_ProjectRoleUserPermissions();
     $roles = $project->getProjectRoleUserPermissions($projectId);
     Phprojekt_Converter_Json::echoConvert($roles);
 }
 /**
  * Saves the settings for one module.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - string <b>moduleName</b>              Name of the module.
  *  - mixed  <b>all other module fields</b> All the fields values to save.
  * </pre>
  *
  * The return is a string in JSON format with:
  * <pre>
  *  - type    => 'success' or 'error'.
  *  - message => Success or error message.
  *  - code    => 0.
  *  - id      => 0.
  * </pre>
  *
  * @throws Phprojekt_PublishedException On error in the action save or wrong id.
  *
  * @return void
  */
 public function jsonSaveAction()
 {
     $module = Cleaner::sanitize('alnum', $this->getRequest()->getParam('moduleName', null));
     $this->setCurrentProjectId();
     $setting = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting');
     $setting->setModule($module);
     $message = $setting->validateSettings($this->getRequest()->getParams());
     if (!empty($message)) {
         $type = "error";
     } else {
         $message = Phprojekt::getInstance()->translate(self::EDIT_TRUE_TEXT);
         $setting->setSettings($this->getRequest()->getParams());
         $type = "success";
     }
     $return = array('type' => $type, 'message' => $message, 'code' => 0, 'id' => 0);
     Phprojekt_Converter_Json::echoConvert($return);
 }
Beispiel #29
0
 /**
  * Returns all the role-user relation with the project.
  *
  * Returns a list of all the roles related to the users under the project with:
  * <pre>
  *  - id    => id of the role.
  *  - name  => Name of the role.
  *  - users => id and display of the users with the role.
  * </pre>
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>id</b> The project id for consult.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetProjectRoleUserRelationAction()
 {
     $projectId = (int) $this->getRequest()->getParam('id');
     $project = Phprojekt_Loader::getModel('Project', 'ProjectRoleUserPermissions');
     $roles = $project->getProjectRoleUserPermissions($projectId);
     Phprojekt_Converter_Json::echoConvert($roles);
 }