function notifyAction($object, $action, $log_data) { if (!$object instanceof ProjectDataObject) { return; } $subscribers = $object->getSubscribers(); if (!is_array($subscribers) || count($subscribers) == 0) { return; } if ($action == ApplicationLogs::ACTION_ADD) { if ($object instanceof Comment) { //self::newObjectComment($object, $subscribers); // check ProjectDataObject::onAddComment() } else { self::objectNotification($object, $subscribers, logged_user(), 'new'); } } else { if ($action == ApplicationLogs::ACTION_EDIT) { self::objectNotification($object, $subscribers, logged_user(), 'modified'); } else { if ($action == ApplicationLogs::ACTION_TRASH) { self::objectNotification($object, $subscribers, logged_user(), 'deleted'); } else { if ($action == ApplicationLogs::ACTION_CLOSE) { self::objectNotification($object, $subscribers, logged_user(), 'closed'); } else { if ($action == ApplicationLogs::ACTION_SUBSCRIBE) { self::objectNotification($object, Users::findByIds(explode(",", $log_data)), logged_user(), 'subscribed'); } } } } } }
/** * Return all users assigned to a specific object * * @param ProjectObject $object * @return array */ function findAssigneesByObject($object) { $cache_id = 'object_assignments_' . $object->getId(); $cached_values = cache_get($cache_id); if (is_array($cached_values)) { if (count($cached_values) > 0) { return Users::findByIds($cached_values); } else { return null; } // if } // if $users_table = TABLE_PREFIX . 'users'; $assignments_table = TABLE_PREFIX . 'assignments'; $cached_values = array(); $rows = db_execute_all("SELECT {$users_table}.id FROM {$users_table}, {$assignments_table} WHERE {$assignments_table}.object_id = ? AND {$assignments_table}.user_id = {$users_table}.id", $object->getId()); if (is_foreachable($rows)) { foreach ($rows as $row) { $cached_values[] = (int) $row['id']; } // foreach } // if cache_set($cache_id, $cached_values); if (count($cached_values) > 0) { return Users::findByIds($cached_values); } else { return null; } // if }
/** * Funzione per ritornare il task array con delle informazioni in più */ private static function getDescribedTaskArray(DBResult $result, Project $active_project, User $logged_user, $items_limit = null) { $return_value = Tasks::getDescribedTaskArray($result, $active_project, $logged_user, $items_limit); // a new array is created $nuovo_ritorno = array(); if ($result instanceof DBResult) { $id_assegnatari = array(); foreach ($result as $row) { if ($row['assignee_id'] && !in_array($row['assignee_id'], $id_assegnatari)) { $id_assegnatari[] = $row['assignee_id']; } //if } $assegnatari_array = count($id_assegnatari) ? Users::findByIds($id_assegnatari)->toArrayIndexedBy('getId') : array(); // Referenza &, non c'è copia. // Per ognuno aggiungo l'assignee e la data di aggiornamento foreach ($return_value as $chiave => &$task) { foreach ($result as $row) { //copio i vecchi valori foreach ($task as $k => $v) { $nuovo_ritorno[$chiave][$k] = $v; } //scorro tutto l'array dei risultati per ottenere la riga con il risultato corretto if ($row['id'] == $task['id']) { $nuovo_ritorno[$chiave]['assignee_id'] = $row['assignee_id'] ? $assegnatari_array[$row['assignee_id']] : null; $nuovo_ritorno[$chiave]['updated_on'] = $row['updated_on'] ? datetimeval($row['updated_on']) : $row['created_on']; } } } } // if return $nuovo_ritorno; }
/** * Render select assignees box * * Parameters: * * - object - Parent object * - project - Show only users that have access to this project * - company - SHow only users that are members of tis company * - exclude - ID-s of users that need to be excluded * - value - Array of selected users as first element and ID of task * owner as second * - name - Base name * * @param array $params * @param Smarty $smarty * @return string */ function smarty_function_select_assignees($params, &$smarty) { static $counter = 0; $name = array_var($params, 'name'); if ($name == '') { return new InvalidParamError('name', $name, '$name is expected to be a valid control name', true); } // if $id = array_var($params, 'id'); if (empty($id)) { $counter++; $id = 'select_assignees_' . $counter; } // if $exclude_ids = array_var($params, 'exclude', array()); if (is_foreachable($exclude_ids) && is_foreachable($selected_user_ids)) { foreach ($selected_user_ids as $k => $v) { if (in_array($v, $exclude_ids)) { unset($selected_user_ids[$k]); } // if } // foreach } // if $value = array_var($params, 'value', array(), true); if (count($value) == 2) { list($selected_user_ids, $owner_id) = $value; } else { $selected_user_ids = null; $owner_id = null; } // if if (is_foreachable($selected_user_ids)) { $selected_users = Users::findByIds($selected_user_ids); } else { $selected_users = null; } // if $company = array_var($params, 'company'); $project = array_var($params, 'project'); $company_id = 0; if (instance_of($company, 'Company')) { $company_id = $company->getId(); } // if $project_id = 0; if (instance_of($project, 'Project')) { $project_id = $project->getId(); } // if require_once ANGIE_PATH . '/classes/json/init.php'; $smarty->assign(array('_select_assignees_id' => $id, '_select_assignees_name' => $name, '_select_assignees_users' => $selected_users, '_select_assignees_owner_id' => $owner_id, '_select_assignees_company_id' => do_json_encode($company_id), '_select_assignees_project_id' => do_json_encode($project_id), '_select_assignees_exclude_ids' => do_json_encode($exclude_ids))); return $smarty->fetch(get_template_path('_select_assignees', null, RESOURCES_MODULE)); }
/** * Render content for select_users popup dialog * * @param void * @return null */ function select_users() { $company_id = $this->request->getId('company_id'); $company = null; if ($company_id) { $company = Companies::findById($company_id); } // if $project_id = $this->request->getId('project_id'); $project = null; if ($project_id) { $project = Projects::findById($project_id); } // if $exclude_user_ids = $this->request->get('exclude_user_ids'); if ($exclude_user_ids) { $exclude_user_ids = explode(',', $exclude_user_ids); } // if $selected_user_ids = $this->request->get('selected_user_ids'); if ($selected_user_ids) { $selected_user_ids = explode(',', $selected_user_ids); } // if if (is_foreachable($exclude_user_ids) && is_foreachable($selected_user_ids)) { foreach ($selected_user_ids as $k => $v) { if (in_array($v, $exclude_user_ids)) { unset($selected_user_ids[$k]); } // if } // foreach } // if if (is_foreachable($selected_user_ids)) { $selected_users = Users::findByIds($selected_user_ids); } else { $selected_users = null; } // if $grouped_users = Users::findForSelect($company, $project, $exclude_user_ids); $this->smarty->assign(array('widget_id' => $this->request->get('widget_id'), 'grouped_users' => $grouped_users, 'selected_users' => $selected_users, 'selected_users_cycle_name' => $this->request->get('widget_id') . '_select_users')); }
/** * Return associative array of changes that is easy to display * * @param void * @return array */ function getVerboseChanges() { $result = array(); if (is_foreachable($this->getChanges())) { foreach ($this->getChanges() as $field => $change_data) { list($old_value, $new_value) = $change_data; $log_fields = array('project_id', 'milestone_id', 'parent_id', 'name', 'body', 'priority', 'due_on'); switch ($field) { case 'project_id': $old_project = Projects::findById($old_value); $new_project = Projects::findById($new_value); $old_project_name = instance_of($old_project, 'Project') ? $old_project->getName() : lang('unknown project'); $new_project_name = instance_of($new_project, 'Project') ? $new_project->getName() : lang('unknown project'); $result[] = lang('Moved from <span>:from</span> to <span>:to</span>', array('from' => $old_project_name, 'to' => $new_project_name)); break; case 'milestone_id': $old_milestone = Milestones::findById($old_value); $new_milestone = Milestones::findById($new_value); $old_milestone_name = instance_of($old_milestone, 'Milestone') ? $old_milestone->getName() : lang('-- none --'); $new_milestone_name = instance_of($new_milestone, 'Milestone') ? $new_milestone->getName() : lang('-- none --'); $result[] = lang('Moved from <span>:from</span> to <span>:to</span> milestone', array('from' => $old_milestone_name, 'to' => $new_milestone_name)); break; case 'parent_id': $old_parent = ProjectObjects::findById($old_value); $new_parent = ProjectObjects::findById($new_value); $old_parent_name = instance_of($old_parent, 'Category') ? $old_parent->getName() : lang('-- none --'); $new_parent_name = instance_of($new_parent, 'Category') ? $new_parent->getName() : lang('-- none --'); $result[] = lang('Moved from <span>:from</span> to <span>:to</span> category', array('from' => $old_parent_name, 'to' => $new_parent_name)); break; case 'name': $result[] = lang('Summary is changed from <span>:from</span> to <span>:to</span>', array('from' => $old_value, 'to' => $new_value)); break; case 'body': $result[] = lang('Long description is changed'); break; case 'priority': switch ($old_value) { case PRIORITY_HIGHEST: $old_priority = lang('Highest'); break; case PRIORITY_HIGH: $old_priority = lang('High'); break; case PRIORITY_NORMAL: $old_priority = lang('Normal'); break; case PRIORITY_LOW: $old_priority = lang('Low'); break; case PRIORITY_LOWEST: $old_priority = lang('Lowest'); break; case PRIORITY_ONGOING: $old_priority = lang('Ongoing'); break; case PRIORITY_HOLD: $old_priority = lang('Hold'); break; } // switch switch ($new_value) { case PRIORITY_HIGHEST: $new_priority = lang('Highest'); break; case PRIORITY_HIGH: $new_priority = lang('High'); break; case PRIORITY_NORMAL: $new_priority = lang('Normal'); break; case PRIORITY_LOW: $new_priority = lang('Low'); break; case PRIORITY_LOWEST: $new_priority = lang('Lowest'); break; case PRIORITY_ONGOING: $new_priority = lang('Ongoing'); break; case PRIORITY_HOLD: $new_priority = lang('Hold'); break; } // switch $result[] = lang('Priority is changed from <span>:from</span> to <span>:to</span>', array('from' => $old_priority, 'to' => $new_priority)); break; case 'due_on': require_once SMARTY_PATH . '/plugins/modifier.date.php'; $old_due_on = instance_of($old_value, 'DateValue') ? smarty_modifier_date($old_value, 0) : lang('-- none --'); $new_due_on = instance_of($new_value, 'DateValue') ? smarty_modifier_date($new_value, 0) : lang('-- none --'); $result[] = lang('Due date is changed from <span>:from</span> to <span>:to</span>', array('from' => $old_due_on, 'to' => $new_due_on)); break; case 'completed_on': if (instance_of($old_value, 'DateValue') && $new_value === null) { $result[] = lang('Status changed to: Open'); } elseif ($old_value === null && instance_of($new_value, 'DateValue')) { $result[] = lang('Status changed to: Completed'); } // if break; case 'owner': if ($new_value) { $new_owner = Users::findById($new_value); if (instance_of($new_owner, 'User')) { $result[] = lang(':user is responsible', array('user' => $new_owner->getDisplayName())); } else { $result[] = lang('Owner changed (unknown user or deleted in the meantime)'); } // if } else { $result[] = lang('Anyone can pick up and work on this ticket'); } // if break; case 'assignees': $old_assignees = array(); if (is_foreachable($old_value)) { $old_assignees_users = Users::findByIds($old_value); if (is_foreachable($old_assignees_users)) { foreach ($old_assignees_users as $user) { $old_assignees[$user->getId()] = $user->getDisplayName(); } // foreach } // if } // if $new_assignees = array(); if (is_foreachable($new_value)) { $new_assignees_users = Users::findByIds($new_value); if (is_foreachable($new_assignees_users)) { foreach ($new_assignees_users as $user) { $new_assignees[$user->getId()] = $user->getDisplayName(); } // foreach } // if } // if foreach ($new_assignees as $new_assignee_id => $new_assignee) { if (!array_key_exists($new_assignee_id, $old_assignees)) { $result[] = lang(':user has been assigned to this ticket', array('user' => $new_assignee)); } // if } // foreach foreach ($old_assignees as $old_assignee_id => $old_assignee) { if (!array_key_exists($old_assignee_id, $new_assignees)) { $result[] = lang(':user has been removed from this ticket', array('user' => $old_assignee)); } // if } // foreach break; } // switch } // foreach } // if return $result; }
/** * Mass mailer * * @param void * @return null */ function mass_mailer() { if (!MASS_MAILER_ENABLED) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $email_data = $this->request->post('email'); $this->smarty->assign(array('email_data' => $email_data, 'exclude' => array($this->logged_user->getId()))); if ($this->request->isSubmitted()) { $errors = new ValidationErrors(); $subject = trim(array_var($email_data, 'subject')); $body = trim(array_var($email_data, 'body')); $recipient_ids = array_var($email_data, 'recipients'); if (empty($subject)) { $errors->addError(lang('Subject is required'), 'subject'); } // if if (empty($body)) { $errors->addError(lang('Body is required'), 'body'); } // if $recipients = array(); if (is_foreachable($recipient_ids)) { $recipients = Users::findByIds(array_unique($recipient_ids)); } // if if (!is_foreachable($recipients)) { $errors->addError(lang('Please select recipients'), 'recipients'); } // if if ($errors->hasErrors()) { $this->smarty->assign('errors', $errors); $this->render(); } // if $mailer =& ApplicationMailer::mailer(); $message = new Swift_Message($subject, $body, 'text/html', EMAIL_ENCODING, EMAIL_CHARSET); $recipients_list = new Swift_RecipientList(); foreach ($recipients as $recipient) { $name = $recipient->getDisplayName(); $email = $recipient->getEmail(); if ($name == $email) { $name = ''; } // if $recipients_list->add($email, $name); } // foreach $name = $this->logged_user->getDisplayName(); $email = $this->logged_user->getEmail(); if ($name == $email) { $name = ''; } // if if ($mailer->batchSend($message, $recipients_list, new Swift_Address($email, $name))) { flash_success('Email has been successfully sent'); } else { flash_error('Failed to send email'); } // if $this->redirectTo('admin_tools_mass_mailer'); } // if }
private function current_user() { $this->load->model('users'); return Users::findByIds(2); }
/** * Return verbose user filter data * * @param void * @return string */ function getVerboseUserFilterData() { if ($this->verbose_user_filter_data === false) { switch ($this->getUserFilter()) { case USER_FILTER_COMPANY: $company = Companies::findById($this->getUserFilterData()); if (instance_of($company, 'Company')) { $this->verbose_user_filter_data = $company->getName(); } // if break; case USER_FILTER_SELECTED: $user_ids = $this->getUserFilterData(); if (is_foreachable($user_ids)) { $users = Users::findByIds($user_ids); if (is_foreachable($users)) { $user_names = array(); foreach ($users as $user) { $user_names[] = $user->getDisplayName(); } // foreach $this->verbose_user_filter_data = implode(', ', $user_names); } // if } // if break; } // switch } // if return $this->verbose_user_filter_data; }
/** * Add people to the project * * @param void * @return null */ function add_people() { if (!$this->active_project->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $project_users = $this->active_project->getUsers(); if (is_foreachable($project_users)) { $exclude_users = objects_array_extract($project_users, 'getId'); } else { $exclude_users = null; } // if $this->smarty->assign(array('exclude_users' => $exclude_users)); if ($this->request->isSubmitted()) { $user_ids = $this->request->post('users'); if (!is_foreachable($user_ids)) { flash_error('No users selected'); $this->redirectToUrl($this->active_project->getViewUrl()); } // if $users = Users::findByIds($user_ids); $project_permissions = $this->request->post('project_permissions'); $role = null; $role_id = (int) array_var($project_permissions, 'role_id'); if ($role_id) { $role = Roles::findById($role_id); } // if if (instance_of($role, 'Role') && $role->getType() == ROLE_TYPE_PROJECT) { $permissions = null; } else { $permissions = array_var($project_permissions, 'permissions'); if (!is_array($permissions)) { $permissions = null; } // if } // if if (is_foreachable($users)) { db_begin_work(); $added = array(); foreach ($users as $user) { $add = $this->active_project->addUser($user, $role, $permissions); if ($add && !is_error($add)) { $added[] = $user->getDisplayName(); } else { db_rollback(); flash_error('Failed to add ":user" to ":project" project', array('user' => $user->getDisplayName(), 'project' => $this->active_project->getName())); $this->redirectToUrl($this->active_project->getAddPeopleUrl()); } // if } // foreach db_commit(); if ($this->request->isApiCall()) { $this->httpOk(); } else { require_once SMARTY_PATH . '/plugins/function.join.php'; flash_success(':users added to :project project', array('users' => smarty_function_join(array('items' => $added)), 'project' => $this->active_project->getName())); $this->redirectToUrl($this->active_project->getPeopleUrl()); } // if } // if } else { if ($this->request->isApiCall()) { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if } // if }
/** * Handle on_project_object_reassigned event * * @param ProjectObject $object * @param array $old_assignment_data * @param array $new_assignment_data * @return null */ function resources_handle_on_project_object_reassigned(&$object, $old_assignment_data, $new_assignment_data) { if (is_array($old_assignment_data)) { list($old_assignees, $old_owner_id) = $old_assignment_data; } else { $old_assignees = array(); $old_owner_id = 0; } // if if (is_array($new_assignment_data)) { list($new_assignees, $new_owner_id) = $new_assignment_data; } else { $new_assignees = array(); $new_owner_id = 0; } // if // --------------------------------------------------- // Collect user data // --------------------------------------------------- $all_user_ids = array(); //BOF: mod AD /* foreach($old_assignees as $assignee_id) { if(!in_array($assignee_id, $all_user_ids)) { $all_user_ids[] = $assignee_id; } // foreach } // if */ //EOF: mod AD foreach ($new_assignees as $assignee_id) { //BOF: mod AD //if(!in_array($assignee_id, $all_user_ids)) { if (!in_array($assignee_id, $old_assignees)) { //EOF: mod AD $all_user_ids[] = $assignee_id; } // foreach } // if if (is_foreachable($all_user_ids)) { $all_users = Users::findByIds($all_user_ids); } else { return; } // if $user_map = array(); foreach ($all_users as $user) { $user_map[$user->getId()] = $user->getDisplayName(); } // if // --------------------------------------------------- // Prepare changes array // --------------------------------------------------- $changes = array(); // Nobody assigned if ($new_owner_id == 0) { $changes[] = lang('Anyone can pick and complete this task'); if ($old_owner_id && isset($user_map[$old_owner_id])) { $changes[] = lang(':name is no longer responsible for this task', array('name' => $user_map[$old_owner_id])); } // if foreach ($old_assignees as $assignee_id) { if (isset($user_map[$assignee_id])) { $changes[] = lang(':name has been removed from this task', array('name' => $user_map[$assignee_id])); } // if } // foreach // We have new assignees } else { if ($old_owner_id != $new_owner_id) { if (isset($user_map[$new_owner_id])) { $changes[] = lang(':name is responsible for this task', array('name' => $user_map[$new_owner_id])); } // if if ($old_owner_id && isset($user_map[$old_owner_id])) { $changes[] = lang(':name is no longer responsible for this task', array('name' => $user_map[$old_owner_id])); } // if } // if foreach ($new_assignees as $assignee_id) { if (isset($user_map[$assignee_id]) && !in_array($assignee_id, $old_assignees)) { $changes[] = lang(':name has been added to this task', array('name' => $user_map[$assignee_id])); } // if } // foreach foreach ($old_assignees as $assignee_id) { if (isset($user_map[$assignee_id]) && !in_array($assignee_id, $new_assignees)) { $changes[] = lang(':name has been removed from this task', array('name' => $user_map[$assignee_id])); } // if } // foreach } // if //BOF:mod 20111214 /* //BOF:mod 20111214 if(is_foreachable($changes) && is_foreachable($all_users)) { $changes_body = "<p>\n"; foreach($changes as $change) { $changes_body .= "- $change<br />\n"; } // foreach $changes_body .= "</p>"; $owner_company = get_owner_company(); $project = $object->getProject(); // Don't send email to person who made the change foreach($all_users as $k => $user) { if($user->getId() == $object->getUpdatedById()) { unset($all_users[$k]); } // if } // foreach if(is_foreachable($all_users)) { ApplicationMailer::send($all_users, 'resources/task_reassigned', array( 'owner_company_name' => $owner_company->getName(), 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'object_type' => $object->getTypeName(), 'object_name' => $object->getName(), 'object_body' => $object->getFormattedBody(), 'object_url' => $object->getViewUrl(), 'changes_body' => $changes_body, ), $object->getNotificationContext()); } // if } // if //BOF:mod 20111214 */ //BOF:mod 20111214 }
/** * Upload file document page action * * @param void * @return void */ function upload_file() { $this->wireframe->print_button = false; if (!Document::canAdd($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $file = $_FILES['file']; $file_data = $this->request->post('file'); if (!is_array($file_data)) { $file_data = array('category_id' => $this->active_document_category->getId()); } // if require_once SMARTY_PATH . '/plugins/modifier.filesize.php'; $this->smarty->assign(array('file_data' => $file_data, 'max_upload_size' => smarty_modifier_filesize(get_max_upload_size()))); if ($this->request->isSubmitted()) { db_begin_work(); $this->active_document->setAttributes($file_data); if (is_array($file)) { $destination_file = get_available_uploads_filename(); if (move_uploaded_file($file['tmp_name'], $destination_file)) { if (FIX_UPLOAD_PERMISSION !== false) { @chmod($destination_file, FIX_UPLOAD_PERMISSION); } // if $this->active_document->setName($file['name']); $this->active_document->setBody(basename($destination_file)); $this->active_document->setMimeType($file['type']); } // if } // if $this->active_document->setCreatedBy($this->logged_user); $this->active_document->setType('file'); $save = $this->active_document->save(); if ($save && !is_error($save)) { $notify_user_ids = $this->request->post('notify_users'); if (is_foreachable($notify_user_ids)) { $notify_users = Users::findByIds($notify_user_ids); $owner_company = get_owner_company(); if (is_foreachable($notify_users)) { ApplicationMailer::send($notify_users, 'documents/new_upload_file_document', array('document_name' => $this->active_document->getName(), 'created_by_name' => $this->active_document->getCreatedByName(), 'created_by_url' => $this->logged_user->getViewUrl(), 'document_url' => $this->active_document->getViewUrl(), 'owner_company_name' => $owner_company->getName()), $this->active_document); } // if } // if db_commit(); flash_success('Document ":document_name" has been uploaded', array('document_name' => $this->active_document->getName())); $this->redirectTo('documents'); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } // if }