/**
 * Render object assignees list
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_mobile_access_object_assignees($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject class', true);
    }
    // if
    $owner = $object->getResponsibleAssignee();
    if (!instance_of($owner, 'User')) {
        Assignments::deleteByObject($object);
        return lang('No one is responsible');
    }
    // if
    require_once SYSTEM_MODULE_PATH . '/helpers/function.user_link.php';
    $other_assignees = array();
    $assignees = $object->getAssignees();
    if (is_foreachable($assignees)) {
        foreach ($assignees as $assignee) {
            if ($assignee->getId() != $owner->getId()) {
                $other_assignees[] = '<a href="' . mobile_access_module_get_view_url($assignee) . '">' . clean($assignee->getName()) . '</a>';
            }
            // if
        }
        // foreach
    }
    // if
    if (count($other_assignees)) {
        return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '. ' . lang('Other assignees') . ': ' . implode(', ', $other_assignees);
    } else {
        return '<a href="' . mobile_access_module_get_view_url($owner) . '">' . clean($owner->getName()) . '</a> ' . lang('is responsible') . '.';
    }
    // if
}
 private function verifyLink($link, $checkSubmitted, $checkEvaluation)
 {
     if (!empty($link)) {
         $assignments = new Assignments();
         $assignment = $assignments->getFromLink($link, $checkEvaluation);
     }
     if ($assignment === null) {
         $this->_helper->flashMessenger->addMessage("ERROR: Invalid action.");
         $this->_helper->redirector->gotoRoute(array('controller' => 'assignment', 'action' => 'index'), 'default', true);
     }
     if ($checkSubmitted && $assignment->getotevren() == false) {
         $this->_helper->flashMessenger->addMessage("ERROR: This test has been already submitted.");
         $this->_helper->redirector->gotoRoute(array('controller' => 'assignment', 'action' => 'index'), 'default', true);
     }
     return $assignment;
 }
Exemple #3
0
 /**
  * 判断当前用户是否包含某个角色
  * @author wjh 2014-9-13
  * @param string $roleKey 关键字,如 agent_ ,provider_  ,provider_manager
  * @return bool 是否包含
  */
 public static function checkCurrentUserRole($roleKey, $userid = null)
 {
     if (empty($userid)) {
         $userid = BDataHelper::getCurrentUserid();
     }
     $roles = Assignments::model()->findAllByAttributes(array('userid' => $userid));
     $data = BArrayHelper::array_func($roles, function ($k, $v, $userdate = null) {
         return array($v->itemname);
     }, function ($k, $v, $userdata = null) use($roleKey) {
         $rolename = $v->itemname;
         return substr($rolename, 0, strlen($roleKey)) == $roleKey;
     });
     return count($data);
 }
 function set_responsible_status()
 {
     $project_id = $this->request->getId('project_id');
     if ($project_id) {
         $project = Projects::findById($project_id);
     }
     $ticket_id = $this->request->getId('ticket_id');
     if ($ticket_id) {
         $ticket = Tickets::findByTicketId($project, $ticket_id);
     }
     $owner = Assignments::findOwnerByObject($ticket);
     $users = Assignments::findAssigneesByObject($ticket);
     $this->smarty->assign(array('project' => $project, 'ticket' => $ticket, 'users' => $users, 'owner' => $owner, 'ticket_url' => assemble_url('project_ticket', array('project_id' => $project_id, 'ticket_id' => $ticket_id))));
 }
 /**
  * Validate the given data
  *
  * checks for assignments
  * validates
  * returns changed data only
  *
  * @param array $data array('schema' => ( 'fieldlabel' => 'value', ...))
  * @param string $pageid
  * @param string[] $errors validation errors
  * @return AccessDataValidator[]|bool savable data or false on validation error
  */
 public static function validateDataForPage($data, $pageid, &$errors)
 {
     $tosave = array();
     $valid = true;
     $errors = array();
     $assignments = new Assignments();
     $tables = $assignments->getPageAssignments($pageid);
     foreach ($tables as $table) {
         $access = AccessTable::byTableName($table, $pageid);
         $validation = $access->getValidator($data[$table]);
         if (!$validation->validate()) {
             $valid = false;
             $errors = array_merge($errors, $validation->getErrors());
         } else {
             if ($validation->hasChanges()) {
                 $tosave[] = $validation;
             }
         }
     }
     if ($valid) {
         return $tosave;
     }
     return false;
 }
 /**
  * Revokes roles from a user
  * @param int $userid The user's id
  * @param String $roles The roles to revoke
  */
 private function _revokeUser($userid, $roles)
 {
     if ($userid) {
         $auth = Yii::app()->authManager;
         /* @var $auth CDbAuthManager */
         foreach ($roles as $role) {
             if ($role == $this->module->superUser) {
                 $count = Assignments::model()->count("itemname='" . $role . "'");
                 if ($count == 1) {
                     return false;
                 }
             }
             $auth->revoke($role, $userid);
             return true;
         }
     }
 }
Exemple #7
0
 public function actionAssignRole($id)
 {
     // request must be made via ajax
     if (isset($_GET['ajax']) && isset($_GET['role'])) {
         $model = $this->loadModel($id);
         $auth = Yii::app()->authManager;
         $auth->assign($_GET['role'], $id, '', '');
         $role = Assignments::model()->find("itemname='" . $_GET['role'] . "'");
         $this->renderPartial('//includes/role_li', array('user' => $model, 'assignment' => $role), false, true);
     } else {
         throw new CHttpException(400, 'Invalid request.');
     }
 }
 function quickreminder()
 {
     if ($this->active_task->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     if (empty($this->active_task_parent)) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     if (!$this->active_task->canEdit($this->logged_user) && $this->active_task->getProjectId() != TASK_LIST_PROJECT_ID) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
     }
     $task_data = $this->request->post('taskquick');
     if (!is_array($task_data)) {
         $task_data = array('body' => $this->active_task->getBody(), 'priority' => $this->active_task->getPriority(), 'due_on' => $this->active_task->getDueOn(), 'assignees' => Assignments::findAssignmentDataByObject($this->active_task));
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         $query = "select * from healingcrystals_project_object_misc where object_id='" . $this->active_task->getId() . "'";
         $result = mysql_query($query, $link);
         if (mysql_num_rows($result)) {
             $info = mysql_fetch_assoc($result);
             //$task_data['recurring_flag'] = '1';
             //$task_data['recurring_period'] = $info['recurring_period'];
             //if (empty($task_data['recurring_period'])){
             //   $task_data['recurring_flag'] = '0';
             //}
             //$task_data['recurring_period_type'] = $info['recurring_period_type'];
             //$task_data['recurring_period_condition'] = $info['recurring_period_condition'];
             //$task_data['recurring_end_date'] = empty($info['recurring_end_date']) || $info['recurring_end_date']=='0000-00-00' ? '' : dateval($info['recurring_end_date']);
             if (!empty($info['reminder_date']) && $info['reminder_date'] != '0000-00-00 00:00:00') {
                 list($date, $time) = explode(' ', $info['reminder_date']);
                 list($h, $m, $s) = explode(':', $time);
                 $date = dateval($date);
             }
             $task_data['reminder'] = $date;
             $task_data['remindermeridian'] = $h >= 12 ? 'PM' : 'AM';
             $task_data['reminderhours'] = $h > 12 ? $h - 12 : ($h != 0 ? $h : '12');
             $task_data['reminderminutes'] = $m;
             $task_data['auto_email_status'] = $info['auto_email_status'];
         } else {
             //$task_data['recurring_flag'] = '0';
             //$task_data['recurring_period'] = '';
             //$task_data['recurring_period_type'] = 'D';
             //$task_data['recurring_period_condition'] = 'after_due_date';
             //$task_data['recurring_end_date'] = '';
             $task_data['reminder'] = '';
             $task_data['reminderhours'] = '';
             $task_data['reminderminutes'] = '';
             $task_data['remindermeridian'] = '';
             $task_data['auto_email_status'] = '';
         }
         mysql_close($link);
     }
     $this->smarty->assign('task_data', $task_data);
     $refresh_task_content_mode = false;
     if ($this->request->isSubmitted()) {
         if (!isset($task_data['assignees'])) {
             $task_data['assignees'] = array(array(), 0);
         }
         db_begin_work();
         $old_name = $this->active_task->getBody();
         $this->active_task->setAttributes($task_data);
         $save = $this->active_task->save();
         if ($save && !is_error($save)) {
             db_commit();
             $reminder = dateval($task_data['reminder']);
             $reminderhours = (int) $task_data['reminderhours'];
             $reminderminutes = (int) $task_data['reminderminutes'];
             $remindermeridian = $task_data['remindermeridian'];
             if (!empty($reminder)) {
                 if (!empty($remindermeridian) && $remindermeridian == 'PM' && $reminderhours < 12) {
                     $reminderhours += 12;
                 } elseif (!empty($remindermeridian) && $remindermeridian == 'AM' && $reminderhours == 12) {
                     $reminderhours = 0;
                 }
                 $reminder = $reminder . ' ' . $reminderhours . ':' . $reminderminutes;
             }
             $email_flag = empty($task_data['email_flag']) ? '0' : '1';
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             $query = "select * from healingcrystals_project_object_misc where object_id='" . $this->active_task->getId() . "'";
             $result = mysql_query($query, $link);
             if (mysql_num_rows($result)) {
                 $query01 = "update healingcrystals_project_object_misc set reminder_date='" . $reminder . "', auto_email_status='" . $email_flag . "', last_modified=now() where object_id='" . $this->active_task->getId() . "'";
                 mysql_query($query01, $link);
             } else {
                 $query01 = "insert into healingcrystals_project_object_misc\n                                    (object_id,\n                                     reminder_date,\n                                     recurring_period,\n                                     recurring_period_type,\n                                     recurring_period_condition,\n                                     recurring_end_date,\n                                     date_added,\n                                     auto_email_status) values\n                                     ('" . $this->active_task->getId() . "',\n                                      '" . $reminder . "',\n                                      null,\n                                      null,\n                                      null,\n                                      null,\n                                      now(),\n                                      '" . $email_flag . "')";
                 mysql_query($query01, $link);
             }
             mysql_close($link);
             /*if($this->request->isApiCall()) {
             			$this->serveData($this->active_task, 'task');
             		} else {
             			flash_success('Task ":name" has been updated', array('name' => str_excerpt(strip_tags($old_name), 80, '...')), false, false);
             			$this->redirectToUrl($this->active_task_parent->getViewUrl() . '#task' . $this->active_task->getId());
             		}*/
             $refresh_task_content_mode = true;
         } else {
             db_rollback();
             if ($this->request->isApiCall()) {
                 $this->serveData($save);
             } else {
                 $this->smarty->assign('errors', $save);
             }
         }
     } else {
         if ($this->request->isApiCall()) {
             $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true);
         }
     }
     $this->smarty->assign('refresh_task_content_mode', $refresh_task_content_mode);
 }
Exemple #9
0
 public static function createUser($credential, $profile, $role = "Member")
 {
     $password = $credential->password;
     $credential->salt = SecurityUtils::generateSalt($credential->email_id);
     $credential->activation_code = SecurityUtils::generateRandomString(10);
     $credential->registered_ip = SecurityUtils::getRealIp();
     $credential->password = SecurityUtils::encryptPassword($credential->password, $credential->salt);
     $credential->password_confirm = $credential->password;
     if ($credential->save()) {
         $profile->user_id = $credential->id;
         if ($profile->save()) {
             $assignment = new Assignments();
             $assignment->itemname = $role;
             $assignment->userid = $credential->id;
             $assignment->data = 's:0:"";';
             $assignment->save();
             return array('credential' => $credential, 'profile' => $profile);
         } else {
             $credential->delete();
             $credential->setIsNewRecord(true);
             return false;
         }
     } else {
         $credential->password = $password;
         $credential->password_confirm = $password;
         return false;
     }
 }
 /**
  * Update existing ticket
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $mode = $_GET['mode'];
     if (!empty($mode) and $mode == 'reminder_only_update_mode') {
         $this->register_reminder_info($this->active_ticket->getId(), array('date' => dateval($_POST['reminder']), 'period' => $_POST['recurring_period'], 'type' => $_POST['recurring_period_type']));
         $this->redirectToUrl($this->active_ticket->getViewUrl());
     } else {
         $this->wireframe->print_button = false;
         if ($this->request->isApiCall() && !$this->request->isSubmitted()) {
             $this->httpError(HTTP_ERR_BAD_REQUEST);
         }
         // ifs
         if ($this->active_ticket->isNew()) {
             $this->httpError(HTTP_ERR_NOT_FOUND);
         }
         // if
         if (!$this->active_ticket->canEdit($this->logged_user)) {
             $this->httpError(HTTP_ERR_FORBIDDEN);
         }
         // if
         $ticket_data = $this->request->post('ticket');
         if (!is_array($ticket_data)) {
             $ticket_data = array('name' => $this->active_ticket->getName(), 'body' => $this->active_ticket->getBody(), 'visibility' => $this->active_ticket->getVisibility(), 'parent_id' => $this->active_ticket->getParentId(), 'milestone_id' => $this->active_ticket->getMilestoneId(), 'priority' => $this->active_ticket->getPriority(), 'assignees' => Assignments::findAssignmentDataByObject($this->active_ticket), 'tags' => $this->active_ticket->getTags(), 'due_on' => $this->active_ticket->getDueOn());
         }
         // if
         //BOF:mod 20121116
         $options = array();
         $options[] = array('url' => 'javascript:convert_object_to_milestone(\'' . $this->active_ticket->getProjectId() . '\', \'' . $this->active_ticket->getId() . '\', \'' . $this->active_ticket->getType() . '\');', 'text' => 'Milestone');
         $options[] = array('url' => 'javascript:convert_object_to_page(\'' . $this->active_ticket->getProjectId() . '\', \'' . $this->active_ticket->getId() . '\', \'' . $this->active_ticket->getType() . '\');', 'text' => 'Page');
         $this->wireframe->addPageAction(lang('Convert To'), 'javascript://', $options);
         //EOF:mod 20121116
         $this->smarty->assign('ticket_data', $ticket_data);
         $this->smarty->assign('reminder', $this->get_reminder_info($this->active_ticket->getId()));
         //BOF:mod 13052011
         $this->smarty->assign('ticket_id', $this->active_ticket->getId());
         //EOF:mod 13052011
         if ($this->request->isSubmitted()) {
             if (!isset($ticket_data['assignees'])) {
                 $ticket_data['assignees'] = array(array(), 0);
             }
             // if
             db_begin_work();
             $this->active_ticket->setAttributes($ticket_data);
             $save = $this->active_ticket->save();
             if ($save && !is_error($save)) {
                 db_commit();
                 //BOF: mod
                 $this->active_ticket->register_departments(!empty($ticket_data['departments']) ? $ticket_data['departments'] : array());
                 $this->register_reminder_info($this->active_ticket->getId(), array('date' => dateval($ticket_data['reminder']), 'period' => $ticket_data['recurring_period'], 'type' => $ticket_data['recurring_period_type']));
                 //EOF: mod
                 $assignees_flag_data = $this->request->post('assignee');
                 $this->active_ticket->register_assignees_flag($assignees_flag_data);
                 //BOF:mod 13052011
                 //if ($ticket_data['flag_fyi'] || $ticket_data['flag_actionrequest']){
                 //	$this->register_flag_fyi_actionrequest($ticket_data['flag_fyi'], $ticket_data['flag_actionrequest']);
                 //}
                 //EOF:mod 13052011
                 if ($ticket_data['new_team_id'] != $this->active_project->getId()) {
                     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                     mysql_select_db(DB_NAME);
                     $query = "select max(integer_field_1) as count from healingcrystals_project_objects where project_id='" . $ticket_data['new_team_id'] . "' and type='Ticket'";
                     $result = mysql_query($query, $link);
                     $cur_ticket_id = '1';
                     if (mysql_num_rows($result)) {
                         $info = mysql_fetch_assoc($result);
                         if ($info['count']) {
                             $cur_ticket_id = (int) $info['count'] + 1;
                         }
                     }
                     $query = "update healingcrystals_project_objects set project_id='" . $ticket_data['new_team_id'] . "', milestone_id=null, integer_field_1='" . $cur_ticket_id . "', updated_on=now(), updated_by_id='" . $this->logged_user->getId() . "' where id='" . $this->active_ticket->getId() . "' and project_id='" . $this->active_project->getId() . "'";
                     mysql_query($query);
                     $query = "update healingcrystals_project_objects set project_id='" . $ticket_data['new_team_id'] . "', milestone_id=null, updated_on=now(), updated_by_id='" . $this->logged_user->getId() . "' where parent_id='" . $this->active_ticket->getId() . "' and project_id='" . $this->active_project->getId() . "'";
                     mysql_query($query);
                     mysql_close($link);
                     $this->redirectToUrl(assemble_url('project_ticket', array('project_id' => $ticket_data['new_team_id'], 'ticket_id' => $cur_ticket_id)));
                 }
                 if ($this->request->getFormat() == FORMAT_HTML) {
                     flash_success('Ticket #:ticket_id has been updated', array('ticket_id' => $this->active_ticket->getTicketId()));
                     $this->redirectToUrl($this->active_ticket->getViewUrl());
                 } else {
                     $this->serveData($this->active_ticket, 'ticket');
                 }
                 // if
             } else {
                 db_rollback();
                 if ($this->request->getFormat() == FORMAT_HTML) {
                     $this->smarty->assign('errors', $save);
                 } else {
                     $this->serveData($save);
                 }
                 // if
             }
             // if
         }
         // if
     }
 }
 /**
  * Edit specific milestone
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->active_milestone->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_milestone->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     //$this->wireframe->addPageMessage(lang('<a href=":url">Click here</a> if you wish to reschedule this milestone', array('url' => $this->active_milestone->getRescheduleUrl())), 'info');
     $this->wireframe->addPageMessage(lang('<a href=":url">Click here</a> if you wish to reschedule this project', array('url' => $this->active_milestone->getRescheduleUrl())), 'info');
     $milestone_data = $this->request->post('milestone');
     if (!is_array($milestone_data)) {
         $milestone_data = array('name' => $this->active_milestone->getName(), 'body' => $this->active_milestone->getBody(), 'start_on' => $this->active_milestone->getStartOn(), 'due_on' => $this->active_milestone->getDueOn(), 'priority' => $this->active_milestone->getPriority(), 'assignees' => Assignments::findAssignmentDataByObject($this->active_milestone), 'tags' => $this->active_milestone->getTags(), 'project_id' => $this->active_milestone->getProjectId(), 'visibility' => $this->active_milestone->getVisibility());
     }
     // if
     //BOF:mod 20121116
     $options = array();
     $options[] = array('url' => 'javascript:convert_object_to_ticket(\'' . $this->active_milestone->getProjectId() . '\', \'' . $this->active_milestone->getId() . '\', \'' . $this->active_milestone->getType() . '\');', 'text' => 'Ticket');
     $options[] = array('url' => 'javascript:convert_object_to_page(\'' . $this->active_milestone->getProjectId() . '\', \'' . $this->active_milestone->getId() . '\', \'' . $this->active_milestone->getType() . '\');', 'text' => 'Page');
     $this->wireframe->addPageAction(lang('Convert To'), 'javascript://', $options);
     //EOF:mod 20121116
     $this->smarty->assign('milestone_data', $milestone_data);
     //BOF: task 07 | AD
     $this->smarty->assign('is_edit_mode', '1');
     //EOF: task 07 | AD
     if ($this->request->isSubmitted()) {
         if (!isset($milestone_data['assignees'])) {
             $milestone_data['assignees'] = array(array(), 0);
         }
         // if
         db_begin_work();
         $old_name = $this->active_milestone->getName();
         //BOF: task 07 | AD
         $old_project_id = $this->active_milestone->getProjectId();
         //EOF: task 07 | AD
         $this->active_milestone->setAttributes($milestone_data);
         $save = $this->active_milestone->save();
         if ($save && !is_error($save)) {
             db_commit();
             //BOF: task 07 | AD
             //BOF: mod
             $this->active_milestone->register_departments(!empty($milestone_data['departments']) ? $milestone_data['departments'] : array(), implode(',', $milestone_data['departments']));
             //EOF: mod
             //BOF:mod 20110614
             $assignees_flag_data = $this->request->post('assignee');
             $this->active_milestone->register_assignees_flag($assignees_flag_data);
             //EOF:mod 20110614
             if ($old_project_id != $this->active_milestone->getProjectId()) {
                 $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 mysql_select_db(DB_NAME, $link);
                 $query = "select id, integer_field_1 \n\t\t\t\t\t\t\tfrom healingcrystals_project_objects where \n\t\t\t\t\t\t\tmilestone_id ='" . $this->active_milestone->getId() . "' and \n\t\t\t\t\t\t\tproject_id='" . $old_project_id . "' and type='Ticket' and integer_field_1 is not null";
                 $result = mysql_query($query);
                 $next_id = Tickets::findNextTicketIdByProject($this->active_milestone->getProjectId());
                 while ($ticket = mysql_fetch_assoc($result)) {
                     mysql_query("update healingcrystals_project_objects \n\t\t\t\t\t\t\t\t\tset integer_field_1='" . $next_id . "'  \n\t\t\t\t\t\t\t\t\twhere id='" . $ticket['id'] . "'");
                     $next_id++;
                 }
                 $query = "select updated_on, updated_by_id, updated_by_name, integer_field_1 from healingcrystals_project_objects where id='" . $this->active_milestone->getId() . "'";
                 $result = mysql_query($query, $link);
                 $info = mysql_fetch_assoc($result);
                 $query = "update healingcrystals_project_objects set \n\t\t\t\t\t\t\tproject_id ='" . $this->active_milestone->getProjectId() . "', \n\t\t\t\t\t\t\tupdated_on =" . (empty($info['updated_on']) ? "null" : "'" . $info['updated_on'] . "'") . ", \n\t\t\t\t\t\t\tupdated_by_id =" . (empty($info['updated_by_id']) ? "null" : "'" . $info['updated_by_id'] . "'") . ", \n\t\t\t\t\t\t\tupdated_by_name =" . (empty($info['updated_by_name']) ? "null" : "'" . mysql_real_escape_string($info['updated_by_name']) . "'") . ", \n\t\t\t\t\t\t\tupdated_by_email =" . (empty($info['updated_by_email']) ? "null" : "'" . $info['updated_by_email'] . "'") . " \n\t\t\t\t\t\t\twhere milestone_id ='" . $this->active_milestone->getId() . "' and project_id='" . $old_project_id . "'";
                 mysql_query($query);
                 $query = "update healingcrystals_project_objects set category_id=null where id='" . $this->active_milestone->getId() . "'";
                 mysql_query($query);
                 mysql_close($link);
             }
             //EOF: task 07 | AD
             if ($this->request->getFormat() == FORMAT_HTML) {
                 //flash_success('Milestone ":name" has been updated', array('name' => $old_name), false, true);
                 flash_success('Project ":name" has been updated', array('name' => $old_name), false, true);
                 $this->redirectToUrl($this->active_milestone->getViewUrl());
             } else {
                 $this->serveData($this->active_milestone, 'milestone');
             }
             // if
         } else {
             db_rollback();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 $this->smarty->assign('errors', $save);
             } else {
                 $this->serveData($save);
             }
             // if
         }
         // if
     }
     // if
 }
 /**
  * Delete this object
  * 
  * If $drop_subitems is TRUE subitems will be delete from the database. If it 
  * is false relation will be nullified
  *
  * @param boolean $drop_subitems
  * @return boolean
  * @throws DBQueryError
  */
 function delete($drop_subitems = true)
 {
     db_begin_work();
     $delete = parent::delete();
     if (is_error($delete) || !$delete) {
         db_rollback();
         return $delete;
     }
     // if
     $subitems = $this->getSubitems();
     if (is_foreachable($subitems)) {
         foreach ($subitems as $subitem) {
             if ($drop_subitems) {
                 $delete = $subitem->delete();
                 if (is_error($delete)) {
                     db_rollback();
                     return $delete;
                 }
                 // if
             } else {
                 $subitem->setParent(null, false);
                 $save = $subitem->save();
                 if (is_error($save)) {
                     db_rollback();
                     return $save;
                 }
                 // if
             }
             // if
         }
         // foreach
     }
     // if
     StarredObjects::deleteByObject($this);
     // Attachments
     if ($this->can_have_attachments) {
         Attachments::deleteByObject($this);
     }
     // if
     // Subscriptions
     if ($this->can_have_subscribers) {
         Subscriptions::deleteByParent($this);
     }
     // if
     // Asignments
     if ($this->can_have_assignees) {
         Assignments::deleteByObject($this);
     }
     // if
     // Activity log
     if ($this->log_activities) {
         ActivityLogs::deleteByObject($this);
     }
     // if
     // Reminders
     if ($this->can_send_reminders) {
         Reminders::deleteByObject($this);
     }
     // if
     search_index_remove($this->getId(), 'ProjectObject');
     db_commit();
     return true;
 }
 /**
  * Delete assignments by User
  *
  * @param User $user
  * @return boolean
  */
 function deleteByUser($user)
 {
     cache_remove('user_assignments_' . $user->getId());
     return Assignments::delete(array('user_id = ?', $user->getId()));
 }
/**
 * Hnalde on_project_object_copied event
 *
 * @param ProjectObject $original
 * @param ProjectObject $copy
 * @param Project $destination
 * @param mixed $cascade
 * @return null
 */
function resources_handle_on_project_object_copied(&$original, &$copy, &$destination, $cascade)
{
    if ($original->can_have_subscribers) {
        $subscribers = $original->getSubscribers();
        if (is_foreachable($subscribers)) {
            foreach ($subscribers as $subscriber) {
                if ($subscriber->isProjectMember($destination)) {
                    Subscriptions::subscribe($subscriber, $copy);
                }
                // if
            }
            // foreach
        }
        // if
    }
    // if
    if ($original->can_have_assignees) {
        Assignments::cloneAssignments($original, $copy);
    }
    // if
    if ($original->can_have_attachments) {
        Attachments::cloneAttachments($original, $copy);
    }
    // if
    // Copy child objects
    if ($cascade === true || is_foreachable($cascade)) {
        if ($cascade === true) {
            $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ?', $original->getId());
        } else {
            $rows = db_execute_all('SELECT * FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ? AND type IN (?)', $original->getId(), $cascade);
        }
        // if
        if (is_foreachable($rows)) {
            // We'll remember original and copy tasks ID-s here so we can move
            // assignments later on, when we have both instances
            $tasks = array();
            foreach ($rows as $row) {
                $subobject_original_id = $row['id'];
                $subobject_original_type = strtolower($row['type']);
                unset($row['id']);
                $row['project_id'] = $destination->getId();
                $row['parent_id'] = $copy->getId();
                $row['milestone_id'] = 0;
                // Copy file
                if ($subobject_original_type == 'attachment') {
                    $path = UPLOAD_PATH . '/' . $row['varchar_field_1'];
                    if (is_file($path)) {
                        $destination_file = get_available_uploads_filename();
                        if (copy($path, $destination_file)) {
                            $row['varchar_field_1'] = basename($destination_file);
                        }
                        // if
                    }
                    // if
                }
                // if
                // Escape values
                foreach ($row as $k => $v) {
                    $row[$k] = db_escape($v);
                }
                // foreach
                db_execute('INSERT INTO ' . TABLE_PREFIX . 'project_objects (' . implode(', ', array_keys($row)) . ') VALUES (' . implode(', ', $row) . ')');
                if ($subobject_original_type == 'task') {
                    $tasks[$subobject_original_id] = db_last_insert_id();
                }
                // if
            }
            // foraech
            if (instance_of($copy, 'Discussion')) {
                $last_comment = $copy->getLastComment();
                $last_comment_datetime = instance_of($last_comment, 'Comment') ? $last_comment->getCreatedOn() : null;
                $copy->setLastCommentOn($last_comment_datetime);
                $copy->save();
            }
            // if
            // Lets move task assinments if we have any tasks
            if (is_foreachable($tasks)) {
                foreach ($tasks as $task_original_id => $task_copy_id) {
                    $task_original = Tasks::findById($task_original_id);
                    $task_copy = Tasks::findById($task_copy_id);
                    if (instance_of($task_original, 'Task') && instance_of($task_copy, 'Task')) {
                        Assignments::cloneAssignments($task_original, $task_copy);
                        Subscriptions::cloneSubscriptions($task_original, $task_copy);
                    }
                    // if
                }
                // foreach
            }
            // if
        }
        // if
    }
    // if
}
 /**
  * Delete from database
  *
  * @param void
  * @return boolean
  */
 function delete()
 {
     db_begin_work();
     $delete = parent::delete();
     if ($delete && !is_error($delete)) {
         unlink($this->getAvatarPath());
         unlink($this->getAvatarPath(true));
         ProjectUsers::deleteByUser($this);
         Assignments::deleteByUser($this);
         Subscriptions::deleteByUser($this);
         StarredObjects::deleteByUser($this);
         PinnedProjects::deleteByUser($this);
         UserConfigOptions::deleteByUser($this);
         Reminders::deleteByUser($this);
         search_index_remove($this->getId(), 'User');
         $cleanup = array();
         event_trigger('on_user_cleanup', array(&$cleanup));
         if (is_foreachable($cleanup)) {
             foreach ($cleanup as $table_name => $fields) {
                 foreach ($fields as $field) {
                     $condition = '';
                     if (is_array($field)) {
                         $id_field = array_var($field, 'id');
                         $name_field = array_var($field, 'name');
                         $email_field = array_var($field, 'email');
                         $condition = array_var($field, 'condition');
                     } else {
                         $id_field = $field . '_id';
                         $name_field = $field . '_name';
                         $email_field = $field . '_email';
                     }
                     // if
                     if ($condition) {
                         db_execute('UPDATE ' . TABLE_PREFIX . "{$table_name} SET {$id_field} = 0, {$name_field} = ?, {$email_field} = ? WHERE {$id_field} = ? AND {$condition}", $this->getName(), $this->getEmail(), $this->getId());
                     } else {
                         db_execute('UPDATE ' . TABLE_PREFIX . "{$table_name} SET {$id_field} = 0, {$name_field} = ?, {$email_field} = ? WHERE {$id_field} = ?", $this->getName(), $this->getEmail(), $this->getId());
                     }
                     // if
                 }
                 // foreach
             }
             // foreach
         }
         // if
         db_commit();
         return true;
     } else {
         db_rollback();
         return $delete;
     }
     // if
 }
Exemple #16
0
 /**
  * Check if authorizer is assigned to a user.
  * Until Authorizer is assigned to a user all users have access to srbac
  * administration. Also all users have access to srbac admin if srbac debug
  * attribute is true
  * @return true if authorizer is assigned to a user
  */
 public static function isAuthorizer()
 {
     if (self::findModule('srbac')->debug) {
         return false;
     }
     $criteria = new CDbCriteria();
     $criteria->condition = "itemname = '" . self::findModule('srbac')->superUser . "'";
     $authorizer = Assignments::model()->find($criteria);
     if ($authorizer !== null) {
         return true;
     }
     return false;
 }
Exemple #17
0
 protected function afterDelete()
 {
     parent::afterDelete();
     Assignments::model()->deleteAll("itemname='" . $this->name . "'");
     ItemChildren::model()->deleteAll("parent='" . $this->name . "'");
     ItemChildren::model()->deleteAll("child='" . $this->name . "'");
 }
 /**
  * Clean up system by object ID-s
  * 
  * This function cleans up project objects recursively. It is also infinite 
  * loop safe because it will filter out ID-s that are already removed
  *
  * @param array $ids
  * @return null
  */
 function cleanUpByIds($ids)
 {
     static $cleaned_ids = array();
     // Remove objects that are already cleaned
     if (is_foreachable($ids)) {
         foreach ($ids as $k => $id) {
             if (isset($cleaned_ids[$id]) && $cleaned_ids[$id]) {
                 unset($ids[$k]);
             } else {
                 $cleaned_ids[$id] = false;
             }
             // if
         }
         // foreach
     }
     // if
     if (is_foreachable($ids)) {
         db_begin_work();
         Attachments::deleteByProjectObjectIds($ids);
         Subscriptions::deleteByObjectIds($ids);
         Assignments::deleteByObjectIds($ids);
         ActivityLogs::deleteByObjectIds($ids);
         StarredObjects::deleteByObjectIds($ids);
         Reminders::deleteByObjectIds($ids);
         search_index_remove($ids, 'ProjectObject');
         $rows = db_execute_all('SELECT DISTINCT id FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id IN (?)', $ids);
         if (is_foreachable($rows)) {
             $subobject_ids = array();
             foreach ($rows as $row) {
                 $subobject_ids[] = (int) $row['id'];
             }
             // foreach
             ProjectObjects::cleanUpByIds($subobject_ids);
         }
         // if
         ProjectObjects::delete(array('id IN (?)', $ids));
         foreach ($ids as $id) {
             $cleaned_ids[$id] = true;
         }
         // if
         db_commit();
     }
     // if
     return true;
 }
      <th width="50%">
      <?php 
echo SHtml::label(Helper::translate('srbac', "Task"), 'task');
?>
</th>
      <td width="50%" rowspan="2">
        <div id="operations">
          <?php 
$this->renderPartial('tabViews/taskAjax', array('model' => $model, 'userid' => $userid, 'data' => $data, 'message' => $message));
?>
        </div>
      </td>
    </tr>
    <tr valign="top">
      <td><?php 
echo SHtml::activeDropDownList(Assignments::model(), 'itemname', SHtml::listData(AuthItem::model()->findAll($criteria), 'name', 'name'), array('size' => $this->module->listBoxNumberOfLines, 'class' => 'dropdown', 'ajax' => array('type' => 'POST', 'url' => array('getOpers'), 'update' => '#operations', 'beforeSend' => 'function(){
                      $("#loadMessTask").addClass("srbacLoading");
                  }', 'complete' => 'function(){
                      $("#loadMessTask").removeClass("srbacLoading");
                  }')));
?>
        <div>
          <?php 
echo Helper::translate("srbac", "Clever Assigning");
?>
:
          <?php 
echo SHtml::checkBox("clever", Yii::app()->getGlobalState("cleverAssigning"));
?>
        </div>
      </td>