Exemplo n.º 1
0
 /**
  * Save the settings for the timecard
  *
  * @param array $params $_POST values
  *
  * @return void
  */
 public function setSettings($params)
 {
     $namespace = new Zend_Session_Namespace(Phprojekt_Setting::IDENTIFIER . Phprojekt_Auth::getUserId());
     $fields = $this->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM);
     foreach ($fields as $data) {
         foreach ($params as $key => $value) {
             if ($key == $data['key']) {
                 $setting = new Phprojekt_Setting();
                 $setting->setModule('Timecard');
                 if ($key == 'favorites') {
                     if (count($value) === 1 && $value[0] === "") {
                         $value = array();
                     }
                     $value = serialize($value);
                 }
                 $where = sprintf('user_id = %d AND key_value = %s AND module_id = %d', (int) Phprojekt_Auth::getUserId(), $setting->_db->quote($key), (int) Phprojekt_Module::getId('Timecard'));
                 $record = $setting->fetchAll($where);
                 if (isset($record[0])) {
                     $record[0]->keyValue = $key;
                     $record[0]->value = $value;
                     $record[0]->save();
                 } else {
                     $setting->userId = Phprojekt_Auth::getUserId();
                     $setting->moduleId = Phprojekt_Module::getId('Timecard');
                     $setting->keyValue = $key;
                     $setting->value = $value;
                     $setting->identifier = 'Timecard';
                     $setting->save();
                 }
                 $namespace->{$key} = $value;
                 break;
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Returns the recipients for this Helpdesk item.
  *
  * @return array Array with user IDs.
  */
 public function getTo()
 {
     $userId = Phprojekt_Auth::getUserId();
     // Gets only the recipients with at least a 'read' right.
     $recipients = parent::getTo();
     // Assigned user
     if ($this->_model->assigned != $userId) {
         $recipients[] = $this->_model->assigned;
     }
     // Author user
     if ($this->_model->author != $userId) {
         $recipients[] = $this->_model->author;
     }
     // Owner user
     if ($this->_model->ownerId != $userId) {
         $recipients[] = $this->_model->ownerId;
     }
     // If the item has been reassigned, add the previous assigned user to the recipients
     $history = new Phprojekt_History();
     $olUser = $history->getLastAssignedUser($this->_model, 'assigned');
     if ($olUser > 0) {
         $recipients[] = $olUser;
     }
     // Return without duplicates
     return array_unique($recipients);
 }
Exemplo n.º 3
0
 /**
  * Collect all the values of the settings and return it in one row.
  *
  * @param integer $moduleId The current moduleId.
  * @param array   $metadata Array with all the fields.
  * @param integer $userId   The user ID, if is not setted, the current user is used.
  *
  * @return array Array with all the settings and values.
  */
 public function getList($moduleId, $metadata, $userId = null)
 {
     $setting = new Phprojekt_Setting();
     $setting->setModule('Notification');
     $settings = array();
     if ($userId === null) {
         $userId = (int) Phprojekt_Auth::getUserId();
     }
     $where = sprintf('module_id = %d AND user_id = %d', (int) $moduleId, (int) $userId);
     $record = $setting->fetchAll($where);
     $data = array();
     $data['id'] = 0;
     foreach ($metadata as $meta) {
         $data[$meta['key']] = $meta['default'];
         // This is to use the default value defined in getFieldDefinition()
         foreach ($record as $oneSetting) {
             if ($oneSetting->keyValue == $meta['key']) {
                 $getter = 'get' . ucfirst($oneSetting->keyValue);
                 if (method_exists($this, $getter)) {
                     $data[$meta['key']] = call_user_func(array($this, $getter), $oneSetting->value);
                 } else {
                     $data[$meta['key']] = $oneSetting->value;
                 }
                 break;
             }
         }
     }
     $settings[] = $data;
     return $settings;
 }
Exemplo n.º 4
0
 /**
  * Returns the current effective user.
  *
  * @return Phprojekt_User_User  The current effective user
  */
 public static function getEffectiveUser()
 {
     if (!is_null(self::$_effectiveUser)) {
         return self::$_effectiveUser;
     } else {
         $user = new Phprojekt_User_User();
         return $user->findUserById(Phprojekt_Auth::getUserId());
     }
 }
 /**
  * Creates a subdirectory below this one.
  */
 public function createDirectory($name)
 {
     $filemanager = new Filemanager_Models_Filemanager();
     $filemanager->title = $name;
     $filemanager->projectId = $this->_project->id;
     $filemanager->files = '';
     $filemanager->ownerId = Phprojekt_Auth::getUserId();
     $filemanager->save();
     $rights = $this->_getDefaultRightsForProject($this->_project->id);
     $filemanager->saveRights($rights);
 }
Exemplo n.º 6
0
 /**
  * Return an array of field information.
  *
  * @param integer $ordering An ordering constant.
  *
  * @return array Array with fields definitions.
  */
 public function getFieldDefinition($ordering = Phprojekt_ModelInformation_Default::ORDERING_DEFAULT)
 {
     $meta = parent::getFieldDefinition($ordering);
     // If ownerId != currentUser then set readOnly for all fields except status
     if ($this->_model->ownerId && Phprojekt_Auth::getUserId() != $this->_model->ownerId) {
         foreach (array_keys($meta) as $key) {
             if ('status' != $meta[$key]['key']) {
                 $meta[$key]['readOnly'] = 1;
             }
         }
     }
     return $meta;
 }
Exemplo n.º 7
0
 /**
  * Returns a list of all the active users.
  *
  * Returns a list of all the users with:
  * <pre>
  *  - id      => id of user.
  *  - display => Display for the user.
  *  - current => True or false if is the current user.
  * </pre>
  *
  * The return is in JSON format.
  *
  * @return void
  */
 public function jsonGetUsersAction()
 {
     IndexController::setCurrentProjectId();
     $db = Phprojekt::getInstance()->getDb();
     $user = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
     $records = $user->getAllowedUsers();
     $current = Phprojekt_Auth::getUserId();
     $data = array();
     foreach ($records as $record) {
         $data['data'][] = array('id' => (int) $record['id'], 'display' => $record['name'], 'current' => $current == $record['id']);
     }
     Phprojekt_Converter_Json::echoConvert($data, Phprojekt_ModelInformation_Default::ORDERING_LIST);
 }
Exemplo n.º 8
0
 /**
  * Save each field that is with other value that before.
  *
  * For add actions, the oldValue is empty and all the fields are saved.
  * For delete actions, the newValue is empty and all the fields are saved.
  * For edit action, only the fields with other value that before are saved.
  *
  * @param Phprojekt_Item_Abstract $object The item object.
  * @param string                  $action Action (edit/add/delete).
  *
  * @throws Zend_Exception If the object do not exist.
  *
  * @return void
  */
 public function saveFields(Phprojekt_Item_Abstract $object, $action)
 {
     $differences = $this->_getDifferences($object, $action);
     foreach ($differences as $fieldName => $difference) {
         $history = clone $this;
         $history->userId = Phprojekt_Auth::getUserId();
         $history->moduleId = Phprojekt_Module::getId($object->getModelName());
         $history->itemId = $object->id;
         $history->field = $fieldName;
         $history->oldValue = $difference['oldValue'];
         $history->newValue = $difference['newValue'];
         $history->action = $action;
         $history->datetime = gmdate("Y-m-d H:i:s");
         $history->save();
     }
 }
Exemplo n.º 9
0
 /**
  * Save each field that is with other value that before.
  *
  * For add actions, the oldValue is empty and all the fields are saved.
  * For delete actions, the newValue is empty and all the fields are saved.
  * For edit action, only the fields with other value that before are saved.
  *
  * @param Phprojekt_Item_Abstract $object The item object.
  * @param string                  $action Action (edit/add/delete).
  *
  * @throws Zend_Exception If the object do not exist.
  *
  * @return void
  */
 public function saveFields($object, $action)
 {
     if (is_object($object) === true) {
         $differences = $this->_getDifferences($object, $action);
         foreach ($differences as $fieldName => $difference) {
             $history = clone $this;
             $history->userId = Phprojekt_Auth::getUserId();
             $history->moduleId = Phprojekt_Module::getId($object->getModelName());
             $history->itemId = $object->id;
             $history->field = $fieldName;
             $history->oldValue = $difference['oldValue'];
             $history->newValue = $difference['newValue'];
             $history->action = $action;
             $history->datetime = gmdate("Y-m-d H:i:s");
             $history->save();
         }
     } else {
         throw new Zend_Exception('The object do not exist');
     }
 }
Exemplo n.º 10
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);
 }
Exemplo n.º 11
0
 /**
  * Returns all the events connected with the current one by the parentId,
  * for the logged user as participant.
  * Doesn't return the current event among them.
  *
  * @return array Array of Calendar IDs.
  */
 public function getRelatedEvents()
 {
     $return = array();
     $rootEventId = $this->getRootEventId($this);
     if ($rootEventId > 0) {
         $userId = Phprojekt_Auth::getUserId();
         $where = sprintf('(parent_id = %d OR id = %d) AND id != %d AND participant_id = %d', (int) $rootEventId, (int) $rootEventId, (int) $this->id, (int) $userId);
         $records = $this->fetchAll($where);
         $return = array();
         foreach ($records as $record) {
             if ($record->id != $this->id) {
                 $return[] = $record->id;
             }
         }
     }
     return $return;
 }
Exemplo n.º 12
0
 /**
  * Returns the frontend (realtime) notification(s) to a user. The return format is JSON.
  *
  * Note:
  * At this point a Zend_Session::writeClose() is needed, to avoid blocking of other requests.
  * See http://www.php.net/manual/en/function.session-write-close.php for more details.
  *
  * @return void
  */
 public function jsonGetFrontendMessageAction()
 {
     try {
         Zend_Session::writeClose(false);
     } catch (Exception $error) {
         Phprojekt::getInstance()->getLog()->debug('Error: ' . $error->message);
     }
     $notification = Phprojekt_Loader::getLibraryClass('Phprojekt_Notification_FrontendMessage');
     $userId = (int) Phprojekt_Auth::getUserId();
     $data = $notification->getFrontendMessage($userId);
     $return = array("data" => $data);
     Phprojekt_Converter_Json::echoConvert($return);
 }
Exemplo n.º 13
0
 /**
  * Extension of delete() for don't save the search strings.
  * Only allow delete if the contact is public or the ownerId is the current user.
  *
  * @return void
  */
 public function delete()
 {
     if (!$this->private || $this->private && $this->ownerId == Phprojekt_Auth::getUserId()) {
         $this->deleteUploadFiles();
         $this->_history->saveFields($this, 'delete');
         parent::delete();
     }
 }
Exemplo n.º 14
0
 /**
  * Set some values deppend on the params.
  *
  * Set the author, solvedBy, solvedDate.
  * Also set the rights for each user (owner, assigned and the normal access tab).
  *
  * @return array POST values with some changes.
  */
 public function setParams()
 {
     $args = func_get_args();
     $params = $args[0];
     $model = $args[1];
     $newItem = isset($args[2]) ? $args[2] : false;
     if ($newItem) {
         $params['author'] = (int) Phprojekt_Auth::getUserId();
         $params['date'] = date("Y-m-d");
         if ($params['status'] == Helpdesk_Models_Helpdesk::STATUS_SOLVED) {
             $params['solvedBy'] = (int) Phprojekt_Auth::getUserId();
             $params['solvedDate'] = date("Y-m-d");
         }
     } else {
         // The author comes as a STRING but must be saved as an INT (and it doesn't change since the item creation)
         $params['author'] = (int) $model->author;
     }
     if (!$newItem && isset($params['status'])) {
         if ($params['status'] != Helpdesk_Models_Helpdesk::STATUS_SOLVED) {
             // Status != 'Solved' - The solver should be null (the solved date can't be deleted, but should be)
             $params['solvedBy'] = 0;
         } else {
             // Status 'Solved' - If it has just been changed to this state, save user and date
             if ($model->status != Helpdesk_Models_Helpdesk::STATUS_SOLVED) {
                 $params['solvedBy'] = (int) Phprojekt_Auth::getUserId();
                 $params['solvedDate'] = date("Y-m-d");
             } else {
                 // The solver comes as a STRING but must be saved as an INT (and the Id doesn't change)
                 $params['solvedBy'] = (int) $model->solvedBy;
             }
         }
     }
     return Default_Helpers_Right::addRightsToAssignedUser('assigned', $params, $model, $newItem);
 }
Exemplo n.º 15
0
 /**
  * Help to save a model by setting the models properties.
  * Validation is based on the ModelInformation implementation.
  *
  * @param Phprojekt_Model_Interface $model  The model
  * @param array                     $params The parameters used to feed the model.
  *
  * @throws Exception If validation of parameters fails.
  *
  * @return boolean True for a sucessful save.
  */
 protected static function _saveModel(Phprojekt_Model_Interface $model, array $params)
 {
     foreach ($params as $k => $v) {
         if (isset($model->{$k})) {
             // Don't allow to set the id on save, since it is done by the ActiveRecord
             if (!in_array($k, array('id'))) {
                 $model->{$k} = $v;
             }
         }
     }
     if (empty($model->id)) {
         $newItem = true;
     } else {
         $newItem = false;
     }
     // Set the owner
     if ($newItem && isset($model->ownerId)) {
         $model->ownerId = Phprojekt_Auth::getUserId();
     }
     // Parent Project
     if (isset($model->projectId)) {
         $projectId = $model->projectId;
     } else {
         $projectId = 0;
     }
     // Checks
     $moduleName = Phprojekt_Loader::getModuleFromObject($model);
     $moduleId = Phprojekt_Module::getId($moduleName);
     if (!$model->recordValidate()) {
         $errors = $model->getError();
         $error = array_pop($errors);
         throw new Phprojekt_PublishedException($error['label'] . ': ' . $error['message']);
     } else {
         if (!self::_checkModule($moduleId, $projectId)) {
             throw new Phprojekt_PublishedException('The parent project do not have enabled this module');
         } else {
             if (!self::_checkItemRights($model, $moduleName)) {
                 throw new Phprojekt_PublishedException('You do not have access to do this action');
             } else {
                 // Set the projectId to 1 for global modules
                 if (isset($model->projectId) && Phprojekt_Module::saveTypeIsGlobal($moduleId)) {
                     $model->projectId = 1;
                 }
                 $model->save();
                 // Save access only if the user have "admin" right
                 $itemRights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
                 $check = $itemRights->getRights($moduleId, $model->id);
                 if ($check['currentUser']['admin']) {
                     if ($moduleName == 'Core') {
                         $rights = Default_Helpers_Right::getModuleRights($params);
                     } else {
                         $rights = Default_Helpers_Right::getItemRights($params, $moduleId, $newItem);
                     }
                     if (count($rights) > 0) {
                         $model->saveRights($rights);
                     }
                 }
                 return $model;
             }
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Save the settings into the table.
  *
  * @param array   $params $_POST fields.
  * @param integer $userId The user ID, if is not setted, the current user is used.
  *
  * @return void
  */
 public function setSettings($params, $userId = 0)
 {
     if (!$userId) {
         $userId = Phprojekt_Auth::getUserId();
     }
     if (method_exists($this->getModel(), 'setSettings')) {
         call_user_func(array($this->getModel(), 'setSettings'), $params, $userId);
     } else {
         $namespace = new Zend_Session_Namespace(self::IDENTIFIER . $userId);
         $fields = $this->getModel()->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM);
         foreach ($fields as $data) {
             foreach ($params as $key => $value) {
                 if ($key == $data['key']) {
                     $where = sprintf('user_id = %d AND key_value = %s AND module_id = %d', (int) $userId, $this->_db->quote($key), (int) $this->_moduleId);
                     $record = $this->fetchAll($where);
                     if (isset($record[0])) {
                         $record[0]->keyValue = $key;
                         $record[0]->value = $value;
                         $record[0]->save();
                     } else {
                         $clone = clone $this;
                         $clone->userId = $userId;
                         $clone->moduleId = (int) $this->_moduleId;
                         $clone->keyValue = $key;
                         $clone->value = $value;
                         $clone->identifier = $this->_module;
                         $clone->save();
                     }
                     $namespace->{$key} = $value;
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 17
0
 /**
  * Save the settings into the table.
  *
  * @param array   $params $_POST fields.
  * @param integer $userId The user ID, if is not setted, the current user is used.
  *
  * @return void
  */
 public function setSettings($params, $userId = 0)
 {
     if (!$userId) {
         $userId = Phprojekt_Auth::getUserId();
     }
     $setting = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting');
     $setting->setModule('User');
     if (empty($params['password'])) {
         $password = $setting->getSetting('password', $userId);
     } else {
         $password = Phprojekt_Auth::cryptString($params['password']);
     }
     $namespace = new Zend_Session_Namespace(Phprojekt_Setting::IDENTIFIER, $userId);
     $fields = $this->getFieldDefinition(Phprojekt_ModelInformation_Default::ORDERING_FORM);
     foreach ($fields as $data) {
         foreach ($params as $key => $value) {
             if ($key == $data['key'] && $key != 'oldValue' && $key != 'confirmValue') {
                 $setting = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting');
                 $setting->setModule('User');
                 if ($key == 'password') {
                     $value = $password;
                 }
                 $where = sprintf('user_id = %d AND key_value = %s AND module_id = %d', (int) $userId, $setting->_db->quote($key), 0);
                 $record = $setting->fetchAll($where);
                 if (isset($record[0])) {
                     $record[0]->keyValue = $key;
                     $record[0]->value = $value;
                     $record[0]->save();
                 } else {
                     $setting->userId = $userId;
                     $setting->moduleId = 0;
                     $setting->keyValue = $key;
                     $setting->value = $value;
                     $setting->identifier = 'Core';
                     $setting->save();
                 }
                 $namespace->{$key} = $value;
                 break;
             }
         }
     }
 }
Exemplo n.º 18
0
 /**
  * Delete only the own records
  *
  * @return boolean
  */
 public function delete()
 {
     if ($this->ownerId == Phprojekt_Auth::getUserId()) {
         return parent::delete();
     } else {
         return false;
     }
 }
Exemplo n.º 19
0
 /**
  * Gets only the recipients with at least a 'read' right
  * and checks if the user has disabled/enabled the settings for saving the messages.
  *
  * If no recipient is given, returns an empty array.
  *
  * @return array Array with user IDs.
  */
 public function getRecipients()
 {
     if (false === empty($this->_recipients)) {
         return $this->_recipients;
     }
     $recipients = array();
     if ($this->_model instanceof Phprojekt_Tree_Node_Database || $this->_model instanceof Phprojekt_Model_Interface) {
         $userIds = $this->_model->getUsersRights();
         if (is_array($userIds) && !empty($userIds)) {
             foreach ($userIds as $right) {
                 if ($right['userId'] == Phprojekt_Auth::getUserId() || true === $right['none']) {
                     continue;
                 }
                 $recipients[] = $right['userId'];
             }
         }
     } else {
         $user = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
         $userIds = $user->fetchAll();
         foreach ($userIds as $user) {
             if ($user->id == Phprojekt_Auth::getUserId()) {
                 continue;
             }
             $recipients[] = $user->id;
         }
     }
     return $this->filterRecipientsToSettings($recipients);
 }
Exemplo n.º 20
0
 /**
  * Setter for User ID.
  *
  * @param integer $user Current user ID.
  *
  * @return void
  */
 private function _setUser($user)
 {
     if ($user != 0) {
         $this->_user = $user;
     } else {
         $this->_user = Phprojekt_Auth::getUserId();
     }
 }
Exemplo n.º 21
0
 /**
  * Returns the list of the bookings in the month.
  *
  * The function use Phprojekt_ModelInformation_Default::ORDERING_LIST for get and sort the fields.
  *
  * OPTIONAL request parameters:
  * <pre>
  *  - integer <b>year</b>  Year to consult.
  *  - integer <b>month</b> Month to consult.
  * </pre>
  *
  * The return is in CSV format.
  *
  * @return void
  */
 public function csvListAction()
 {
     $db = Phprojekt::getInstance()->getDb();
     $userId = Phprojekt_Auth::getUserId();
     $year = (int) $this->getRequest()->getParam('year', date("Y"));
     $month = (int) $this->getRequest()->getParam('month', date("m"));
     if (strlen($month) == 1) {
         $month = '0' . $month;
     }
     $where = sprintf('(owner_id = %d AND DATE(start_datetime) LIKE %s)', (int) $userId, $db->quote($year . '-' . $month . '-%'));
     $this->setCurrentProjectId();
     $records = $this->getModelObject()->fetchAll($where, 'start_datetime ASC');
     Phprojekt_Converter_Csv::echoConvert($records);
 }
Exemplo n.º 22
0
 /**
  * Saves a frontend message to the database using the abstract record pattern.
  *
  * Since the actor id is allways the user who calls this method, the actor_id will be set here.
  *
  * @return boolean True on a sucessful save.
  */
 public function saveFrontendMessage()
 {
     $return = '';
     $this->actorId = (int) Phprojekt_Auth::getUserId();
     if (false === is_array($this->recipientId)) {
         $return = parent::save();
     } else {
         $recipient = $this->recipientId;
         foreach ($recipient as $id) {
             $model = clone $this;
             $model->actorId = $this->actorId;
             $model->projectId = $this->projectId;
             $model->itemId = $this->itemId;
             $model->process = $this->process;
             $model->validUntil = $this->validUntil;
             $model->validFrom = $this->validFrom;
             $model->moduleId = $this->moduleId;
             $model->description = $this->description;
             $model->details = $this->details;
             $model->recipientId = $id;
             $model->itemName = $this->itemName;
             $return = $model->save();
         }
     }
     return $return;
 }
Exemplo n.º 23
0
 /**
  * Get all the modules-item with the wordId.
  *
  * @param array   $words    Array with words IDs.
  * @param string  $operator Query operator.
  * @param integer $count    Limit query.
  *
  * @return array Array of results.
  */
 public function searchModuleByWordId($words, $operator = 'AND', $count = 0)
 {
     $ids = array();
     $result = array();
     $rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
     $userId = Phprojekt_Auth::getUserId();
     $db = Phprojekt::getInstance()->getDb();
     foreach ($words as $content) {
         $ids[] = (int) $content['id'];
     }
     if (!empty($ids)) {
         // Search by AND
         if ($operator == 'AND') {
             $sqlString = '';
             $selects = array();
             $first = true;
             while (!empty($ids)) {
                 $id = array_pop($ids);
                 if ($first) {
                     $first = false;
                     if (!empty($ids)) {
                         $selects[] = $db->select()->from('search_word_module', array('item_id'))->where('word_id = ' . (int) $id);
                     } else {
                         $selects[] = $db->select()->from('search_word_module')->where('word_id = ' . (int) $id);
                     }
                 } else {
                     if (!empty($ids)) {
                         $selects[] = $db->select()->from('search_word_module', array('item_id'))->where('word_id = ' . (int) $id . ' AND item_id IN (%s)');
                     } else {
                         $selects[] = $db->select()->from('search_word_module')->where('word_id = ' . (int) $id . ' AND item_id IN (%s)');
                     }
                 }
             }
             $first = true;
             while (!empty($selects)) {
                 $select = array_shift($selects)->__toString();
                 if ($first) {
                     $sqlString = $select;
                     $first = false;
                 } else {
                     $sqlString = sprintf($select, $sqlString);
                 }
             }
             $stmt = $db->query($sqlString);
             $tmpResult = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
         } else {
             // Search By OR
             $where = 'word_id IN (' . implode(', ', $ids) . ')';
             $order = array('module_id ASC', 'item_id DESC');
             $tmpResult = $this->fetchAll($where, $order)->toArray();
         }
         foreach ($tmpResult as $data) {
             // Limit to $count results
             if ((int) $count > 0 && count($result) >= $count) {
                 break;
             }
             // Only fetch records with read access
             if ($rights->getItemRight($data['module_id'], $data['item_id'], $userId) > 0) {
                 $result[$data['module_id'] . '-' . $data['item_id']] = $data;
             }
         }
     }
     return $result;
 }
Exemplo n.º 24
0
 /**
  * Return all the modules with the relation User-Tag.
  *
  * @param integer $tagUserId Relation User-Tag ID.
  *
  * @return array Array with 'itemId' and 'moduleId'.
  */
 public function getModulesByRelationId($tagUserId)
 {
     $foundResults = array();
     $rights = Phprojekt_Loader::getLibraryClass('Phprojekt_Item_Rights');
     $userId = Phprojekt_Auth::getUserId();
     $where = sprintf('tag_user_id = %d', (int) $tagUserId);
     $modules = $this->fetchAll($where, 'item_id DESC');
     foreach ($modules as $moduleData) {
         if ($rights->getItemRight($moduleData->module_id, $moduleData->item_id, $userId) > 0) {
             $foundResults[] = array('itemId' => $moduleData->item_id, 'moduleId' => $moduleData->module_id);
         }
     }
     return $foundResults;
 }
Exemplo n.º 25
0
 /**
  * Checks that the user has permission for modifying the item, in this case for uploading or deleting files.
  * If not, prints an error, terminating script execution.
  *
  * @param Phprojekt_Model_Interface $model  Current module.
  * @param integer                   $itemId Current item id.
  *
  * @return void
  */
 private function _fileCheckWritePermission($model, $itemId)
 {
     $model->find($itemId);
     $rights = $model->getRights();
     if (!$rights['currentUser']['write']) {
         $error = Phprojekt::getInstance()->translate('You don\'t have permission for modifying this item.');
         // Log error
         Phprojekt::getInstance()->getLog()->err("Error: trying to Delete or Upload a file without write access. " . "User Id: " . Phprojekt_Auth::getUserId() . " - Module: " . $this->getRequest()->getModuleName());
         // Show error to user and stop script execution
         die($error);
     }
 }
Exemplo n.º 26
0
 /**
  * Constructs a Phprojekt_Tags_Users.
  *
  * @return void
  */
 public function __construct()
 {
     $this->_user = Phprojekt_Auth::getUserId();
     parent::__construct(array('db' => Phprojekt::getInstance()->getDb()));
 }
Exemplo n.º 27
0
 protected function _currentUserIdIfNull($userId)
 {
     if (is_null($userId)) {
         $userId = Phprojekt_Auth::getUserId();
     }
     return $userId;
 }
Exemplo n.º 28
0
 /**
  * Rewrites parent fetchAll, so that only records with read access are shown.
  *
  * @param string|array $where  Where clause.
  * @param string|array $order  Order by.
  * @param string|array $count  Limit query.
  * @param string|array $offset Query offset.
  * @param string       $select The comma-separated columns of the joined columns.
  * @param string       $join   The join statements.
  *
  * @return Zend_Db_Table_Rowset The rowset with the results.
  */
 public function fetchAll($where = null, $order = null, $count = null, $offset = null, $select = null, $join = null)
 {
     // Only fetch records with read access
     $join .= sprintf(' INNER JOIN item_rights ON (item_rights.item_id = %s
         AND item_rights.module_id = %d AND item_rights.user_id = %d) ', $this->getAdapter()->quoteIdentifier($this->getTableName() . '.id'), Phprojekt_Module::getId($this->getModelName()), Phprojekt_Auth::getUserId());
     // Set where
     if (null !== $where) {
         $where .= ' AND ';
     }
     $where .= ' (' . sprintf('(%s.owner_id = %d OR %s.owner_id IS NULL)', $this->getTableName(), Phprojekt_Auth::getUserId(), $this->getTableName());
     $where .= ' OR (item_rights.access > 0)) ';
     return parent::fetchAll($where, $order, $count, $offset, $select, $join);
 }
Exemplo n.º 29
0
 /**
  * Log the error adding the user id and some extra values.
  *
  * @param string $message The message to log.
  * @param array  $values  Array with values to show.
  *
  * @return void
  */
 private static function _logError($message, $values)
 {
     // Log error
     Phprojekt::getInstance()->getLog()->err($message . " User Id: " . Phprojekt_Auth::getUserId() . " - Values: " . implode(",", $values));
 }
Exemplo n.º 30
0
 /**
  * Sets the recipients according to the received IDs.
  *
  * @param array $recipients Array with user IDs.
  *
  * @return void
  */
 public function setTo($recipients)
 {
     $phpUser = Phprojekt_Loader::getLibraryClass('Phprojekt_User_User');
     $setting = Phprojekt_Loader::getLibraryClass('Phprojekt_Setting');
     foreach ($recipients as $recipient) {
         $email = $setting->getSetting('email', (int) $recipient);
         if ((int) $recipient) {
             $phpUser->find($recipient);
         } else {
             $phpUser->find(Phprojekt_Auth::getUserId());
         }
         $name = trim($phpUser->firstname . ' ' . $phpUser->lastname);
         if (!empty($name)) {
             $name = $name . ' (' . $phpUser->username . ')';
         } else {
             $name = $phpUser->username;
         }
         $this->addTo($email, $name);
     }
 }