/** * Show dashboard index page * * @param void * @return null */ function index() { $logged_user = logged_user(); $active_projects = $logged_user->getActiveProjects(); $activity_log = null; if (is_array($active_projects) && count($active_projects)) { $include_private = $logged_user->isMemberOfOwnerCompany(); $include_silent = $logged_user->isAdministrator(); $project_ids = array(); foreach ($active_projects as $active_project) { $project_ids[] = $active_project->getId(); } // if $activity_log = ApplicationLogs::getOverallLogs($include_private, $include_silent, $project_ids, config_option('dashboard_logs_count', 15)); } // if tpl_assign('today_milestones', $logged_user->getTodayMilestones()); tpl_assign('late_milestones', $logged_user->getLateMilestones()); tpl_assign('active_projects', $active_projects); tpl_assign('activity_log', $activity_log); // Sidebar tpl_assign('online_users', Users::getWhoIsOnline()); tpl_assign('my_projects', $active_projects); $this->setSidebar(get_template_path('index_sidebar', 'dashboard')); }
function purge_trash() { Env::useHelper("permissions"); $days = config_option("days_on_trash", 0); $count = 0; if ($days > 0) { $date = DateTimeValueLib::now()->add("d", -$days); $objects = Objects::findAll(array("conditions" => array("`trashed_by_id` > 0 AND `trashed_on` < ?", $date), "limit" => 100)); foreach ($objects as $object) { $concrete_object = Objects::findObject($object->getId()); if (!$concrete_object instanceof ContentDataObject) { continue; } if ($concrete_object instanceof MailContent && $concrete_object->getIsDeleted() > 0) { continue; } try { DB::beginWork(); if ($concrete_object instanceof MailContent) { $concrete_object->delete(false); } else { $concrete_object->delete(); } ApplicationLogs::createLog($concrete_object, ApplicationLogs::ACTION_DELETE); DB::commit(); $count++; } catch (Exception $e) { DB::rollback(); Logger::log("Error delting object in purge_trash: " . $e->getMessage(), Logger::ERROR); } } } return $count; }
/** * Show dashboard index page * * @param void * @return null */ function index() { trace(__FILE__, 'index() - begin'); $logged_user = logged_user(); $active_projects = $logged_user->getActiveProjects(); $activity_log = null; $projects_activity_log = array(); if (is_array($active_projects) && count($active_projects)) { $include_private = $logged_user->isMemberOfOwnerCompany(); $include_silent = $logged_user->isAdministrator(); $project_ids = array(); foreach ($active_projects as $active_project) { $project_ids[] = $active_project->getId(); $temp_project_logs = ApplicationLogs::getProjectLogs($active_project, $include_private, $include_silent, config_option('dashboard_project_logs_count', 7)); if (isset($temp_project_logs) && is_array($temp_project_logs) && count($temp_project_logs)) { $projects_activity_log[$temp_project_logs[0]->getCreatedOn()->getTimestamp()] = $temp_project_logs; } krsort($projects_activity_log); } // if $activity_log = ApplicationLogs::getOverallLogs($include_private, $include_silent, $project_ids, config_option('dashboard_logs_count', 15)); } // if trace(__FILE__, 'index() - tpl_assign...'); tpl_assign('today_milestones', $logged_user->getTodayMilestones()); tpl_assign('late_milestones', $logged_user->getLateMilestones()); tpl_assign('active_projects', $active_projects); tpl_assign('activity_log', $activity_log); tpl_assign('projects_activity_log', $projects_activity_log); // Sidebar tpl_assign('online_users', Users::getWhoIsOnline()); tpl_assign('my_projects', $active_projects); $this->setSidebar(get_template_path('index_sidebar', 'dashboard')); trace(__FILE__, 'index() - end'); }
/** * Delete specific user * * @access public * @param void * @return null */ function delete() { $this->setTemplate('del_user'); $user = Users::findById(get_id()); if (!$user instanceof User) { flash_error(lang('user dnx')); $this->redirectTo('administration'); } // if if (!$user->canDelete(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $delete_data = array_var($_POST, 'deleteUser'); tpl_assign('user', $user); tpl_assign('delete_data', $delete_data); if (!is_array($delete_data)) { $delete_data = array('really' => 0, 'password' => ''); // array tpl_assign('delete_data', $delete_data); } else { if ($delete_data['really'] == 1) { $password = $delete_data['password']; if (trim($password) == '') { tpl_assign('error', new Error(lang('password value missing'))); return $this->render(); } if (!logged_user()->isValidPassword($password)) { tpl_assign('error', new Error(lang('invalid login data'))); return $this->render(); } try { DB::beginWork(); $user->delete(); ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_DELETE); DB::commit(); flash_success(lang('success delete user', $user->getDisplayName())); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete user')); } // try $this->redirectToUrl($user->getCompany()->getViewUrl()); } else { flash_error(lang('error delete user')); $this->redirectToUrl($user->getCompany()->getViewUrl()); } } }
function purge_trash() { Env::useHelper("permissions"); $days = config_option("days_on_trash", 0); $count = 0; if ($days > 0) { $date = DateTimeValueLib::now()->add("d", -$days); $managers = array('Comments', 'Companies', 'Contacts', 'MailContents', 'ProjectCharts', 'ProjectEvents', 'ProjectFiles', 'ProjectFileRevisions', 'ProjectForms', 'ProjectMessages', 'ProjectMilestones', 'ProjectTasks', 'ProjectWebpages'); foreach ($managers as $manager_class) { $manager = new $manager_class(); $prevcount = -1; while ($prevcount != $count) { $prevcount = $count; if ($manager_class == 'MailContents') { $objects = $manager->findAll(array("include_trashed" => true, "conditions" => array("`trashed_by_id` > 0 AND `trashed_on` < ? AND `is_deleted` = 0", $date), "limit" => 100)); } else { $objects = $manager->findAll(array("include_trashed" => true, "conditions" => array("`trashed_by_id` > 0 AND `trashed_on` < ?", $date), "limit" => 100)); } if (is_array($objects)) { // delete one by one because each one knows what else to delete foreach ($objects as $o) { try { DB::beginWork(); $ws = $o->getWorkspaces(); if ($o instanceof MailContent) { $o->delete(false); } else { $o->delete(); } ApplicationLogs::createLog($o, $ws, ApplicationLogs::ACTION_DELETE); DB::commit(); $count++; } catch (Exception $e) { DB::rollback(); Logger::log("Error deleting object in purge_trash: " . $e->getMessage(), Logger::ERROR); } } } } } } return $count; }
/** * Delete comment * * @access public * @param void * @return null */ function delete_comment() { $comment = MessageComments::findById(get_id()); if (!$comment instanceof MessageComment) { flash_error(lang('comment dnx')); $this->redirectTo('message'); } // if $message = $comment->getMessage(); if (!$message instanceof ProjectMessage) { flash_error(lang('message dnx')); $this->redirectTo('message'); } // if if (!$comment->canDelete(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToUrl($message->getViewUrl()); } // if try { DB::beginWork(); $comment->delete(); ApplicationLogs::createLog($comment, active_project(), ApplicationLogs::ACTION_DELETE); DB::commit(); flash_success(lang('success delete comment')); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete comment')); } // try $this->redirectToUrl($message->getViewUrl()); }
/** * Return manager instance * * @access protected * @param void * @return ApplicationLogs */ function manager() { if (!$this->manager instanceof ApplicationLogs) { $this->manager = ApplicationLogs::instance(); } return $this->manager; }
/** * Delete specific project form * * @param void * @return null */ function delete() { $project_form = ProjectForms::findById(get_id()); if (!$project_form instanceof ProjectForm) { flash_error(lang('project form dnx')); if (ProjectForm::canAdd(logged_user(), active_project())) { $this->redirectTo('form'); } else { $this->redirectToUrl(active_project()->getOverviewUrl()); } // if } // if if (!$project_form->canDelete(logged_user())) { flash_error(lang('no access permissions')); if (ProjectForm::canAdd(logged_user(), active_project())) { $this->redirectTo('form'); } else { $this->redirectToUrl(active_project()->getOverviewUrl()); } // if } // if if ($project_form->delete()) { ApplicationLogs::createLog($project_form, active_project(), ApplicationLogs::ACTION_DELETE, true); flash_success(lang('success delete project form', $project_form->getName())); } else { flash_error(lang('error delete project form')); } // if $this->redirectTo('form'); }
/** * List project activities as a RSS feed * * @param void * @return null */ function project_activities() { $this->setLayout('xml'); $logged_user = $this->loginUserByToken(); if (!$logged_user instanceof User) { header("HTTP/1.0 404 Not Found"); die; } // if $project = Projects::findById(array_var($_GET, 'project')); if (!$project instanceof Project) { header("HTTP/1.0 404 Not Found"); die; } // if if (!$logged_user->isProjectUser($project)) { header("HTTP/1.0 404 Not Found"); die; } // if $include_private = $logged_user->isMemberOfOwnerCompany(); $include_silent = $logged_user->isAdministrator(); $activity_log = ApplicationLogs::getOverallLogs($include_private, $include_silent, array($project->getId()), config_option('feed_logs_count', 50)); $feed = new Angie_Feed(lang('recent project activities feed', $project->getName()), undo_htmlspecialchars($project->getOverviewUrl())); $feed = $this->populateFeedFromLog($feed, $activity_log); $this->renderText($feed->renderRSS2(), true); }
/** * Delete specific comment * * @param void * @return null */ function delete() { $comment = Comments::findById(get_id()); if (!$comment instanceof Comment) { flash_error(lang('comment dnx')); ajx_current("empty"); return; } // if $object = $comment->getRelObject(); if (!$object instanceof ContentDataObject) { flash_error(lang('object dnx')); ajx_current("empty"); return; } // if if (trim($object->getObjectUrl())) { $redirect_to = $object->getObjectUrl(); } if (!$comment->canDelete(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if try { DB::beginWork(); $comment->trash(); ApplicationLogs::createLog($comment, ApplicationLogs::ACTION_TRASH); DB::commit(); flash_success(lang('success delete comment')); ajx_current("reload"); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete comment')); ajx_current("empty"); } // try }
/** * Delete company logo * * @param void * @return null */ function delete_logo() { if (!logged_user()->isAdministrator(owner_company())) { flash_error(lang('no access permissions')); $this->redirectTo('dashboard'); } // if $company = Companies::findById(get_id()); if (!$company instanceof Company) { flash_error(lang('company dnx')); $this->redirectToReferer(get_url('administration', 'clients')); } // if try { DB::beginWork(); $company->deleteLogo(); $company->save(); ApplicationLogs::createLog($company, null, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success delete company logo')); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete company logo')); } // try $this->redirectToUrl($company->getEditLogoUrl()); }
function restore_user() { $user = Contacts::findById(get_id()); if (!($user instanceof Contact && $user->isUser())) { flash_error(lang('user dnx')); ajx_current("empty"); return; } if (!$user->canDelete(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } try { DB::beginWork(); $user->setDisabled(false); $user->unarchive(); ApplicationLogs::createLog($user, ApplicationLogs::ACTION_UNTRASH); $ret = null; Hook::fire("user_restored", $user, $ret); DB::commit(); flash_success('success delete user'); ajx_current("reload"); } catch (Exception $e) { flash_error($e->getMessage()); DB::rollback(); ajx_current("empty"); } }
/** * Mass set is_private for a given type. If $ids is present limit update only to object with given ID-s * * @param boolean $is_private * @param string $type * @parma array $ids * @return boolean */ static function setIsPrivateForType($is_private, $type, $ids = null) { $limit_ids = null; if (is_array($ids)) { $limit_ids = array(); foreach ($ids as $id) { $limit_ids[] = DB::escape($id); } // if $limit_ids = count($limit_ids) > 0 ? implode(',', $limit_ids) : null; } // if $sql = DB::prepareString('UPDATE ' . ApplicationLogs::instance()->getTableName(true) . ' SET `is_private` = ? WHERE `rel_object_manager` = ?', array($is_private, $type)); if ($limit_ids !== null) { $sql .= " AND `rel_object_id` IN ({$limit_ids})"; } // if return DB::execute($sql); }
function delete_chart() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $chart = ProjectCharts::findById(get_id()); if (!$chart instanceof ProjectChart) { flash_error(lang('chart dnx')); ajx_current("empty"); return; } // if if (!$chart->canDelete(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if try { DB::beginWork(); $chart->trash(); ApplicationLogs::createLog($chart, $chart->getWorkspaces(), ApplicationLogs::ACTION_TRASH); DB::commit(); flash_success(lang('success deleted chart', $chart->getTitle())); ajx_current("back"); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete chart')); ajx_current("empty"); } // try }
function repetitive_task_related_edit($task, $task_data) { $was_template = $task->getIsTemplate(); $task->setFromAttributes($task_data); $task->setIsTemplate($was_template); // is_template value must not be changed from ui $totalMinutes = array_var($task_data, 'time_estimate_hours') * 60 + array_var($task_data, 'time_estimate_minutes'); $task->setTimeEstimate($totalMinutes); if ($task->getParentId() > 0 && $task->hasChild($task->getParentId())) { flash_error(lang('task child of child error')); ajx_current("empty"); return; } DB::beginWork(); $task->save(); $task->setObjectName(array_var($task_data, 'name')); $task->save(); // dependencies if (config_option('use tasks dependencies')) { $previous_tasks = array_var($task_data, 'previous'); if (is_array($previous_tasks)) { foreach ($previous_tasks as $ptask) { if ($ptask == $task->getId()) { continue; } $dep = ProjectTaskDependencies::findById(array('previous_task_id' => $ptask, 'task_id' => $task->getId())); if (!$dep instanceof ProjectTaskDependency) { $dep = new ProjectTaskDependency(); $dep->setPreviousTaskId($ptask); $dep->setTaskId($task->getId()); $dep->save(); } } $saved_ptasks = ProjectTaskDependencies::findAll(array('conditions' => 'task_id = ' . $task->getId())); foreach ($saved_ptasks as $pdep) { if (!in_array($pdep->getPreviousTaskId(), $previous_tasks)) { $pdep->delete(); } } } else { ProjectTaskDependencies::delete('task_id = ' . $task->getId()); } } // Add assigned user to the subscibers list if ($task->getAssignedToContactId() > 0 && Contacts::instance()->findById($task->getAssignedToContactId())) { if (!isset($_POST['subscribers'])) { $_POST['subscribers'] = array(); } $_POST['subscribers']['user_' . $task->getAssignedToContactId()] = 'checked'; } $object_controller = new ObjectController(); $object_controller->add_to_members($task, array_var($task_data, 'members')); $object_controller->add_subscribers($task); $object_controller->link_to_new_object($task); $object_controller->add_custom_properties($task); $object_controller->add_reminders($task); // apply values to subtasks $assigned_to = $task->getAssignedToContactId(); $subtasks = $task->getAllSubTasks(); $milestone_id = $task->getMilestoneId(); $apply_ms = array_var($task_data, 'apply_milestone_subtasks') == "checked"; $apply_at = array_var($task_data, 'apply_assignee_subtasks', '') == "checked"; foreach ($subtasks as $sub) { $modified = false; if ($apply_at || !($sub->getAssignedToContactId() > 0)) { $sub->setAssignedToContactId($assigned_to); $modified = true; } if ($apply_ms) { $sub->setMilestoneId($milestone_id); $modified = true; } if ($modified) { $sub->save(); } } $task->resetIsRead(); ApplicationLogs::createLog($task, ApplicationLogs::ACTION_EDIT); DB::commit(); }
/** * Set the status for marked time items * * @access public * @param void * @return null */ function setstatus() { if (!logged_user()->isAdministrator(owner_company())) { flash_error(lang('no access permissions')); $this->redirectTo('dashboard'); } // if $status = array_var($_GET, 'status') ? array_var($_GET, 'status') : 0; $new_status = abs($status - 1); $new_status_text = $new_status ? 'billed' : 'unbilled'; $items = array_var($_POST, 'item'); $redirect_to = array_var($_GET, 'redirect_to'); if ($redirect_to == '') { $redirect_to = get_url('administration', 'time', array('status' => $status)); $redirect_to = str_replace('&', '&', trim($redirect_to)); } // if if (is_array($items) && count($items)) { foreach ($items as $id => $status) { $time = ProjectTimes::findById($id); if (!$time instanceof ProjectTime) { flash_error(lang('time dnx')); $this->redirectToUrl($redirect_to); } // if $time->setIsClosed($new_status); try { DB::beginWork(); $time->save(); ApplicationLogs::createLog($time, $time->getProject(), ApplicationLogs::ACTION_EDIT); DB::commit(); } catch (Exception $e) { DB::rollback(); flash_error('There was an error changing the status of one of your items.'); $this->redirectToUrl($redirect_to); } // try } // foreach flash_success('Items successfully marked as ' . $new_status_text); } // if $this->redirectToUrl($redirect_to); }
function unarchive() { if (!can_manage_dimension_members(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $member = Members::findById(get_id()); if (!$member instanceof Member) { flash_error(lang('member dnx')); ajx_current("empty"); return; } if (get_id('user')) { $user = Contacts::findById($get_id('user')); } else { $user = logged_user(); } if (!$user instanceof Contact) { ajx_current("empty"); return; } try { DB::beginWork(); set_time_limit(0); $count = $member->unarchive($user); evt_add("reload dimension tree", array('dim_id' => $member->getDimensionId())); if (array_var($_REQUEST, 'dont_back')) { ajx_current("empty"); } else { ajx_current("back"); } flash_success(lang('success unarchive member', $member->getName(), $count)); DB::commit(); ApplicationLogs::createLog($member, ApplicationLogs::ACTION_UNARCHIVE); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } }
function list_all() { ajx_current("empty"); $context = active_context(); $start = array_var($_GET, 'start', 0); $limit = array_var($_GET, 'limit', config_option('files_per_page')); $order = array_var($_GET, 'sort'); if ($order == "updatedOn" || $order == "updated" || $order == "date" || $order == "dateUpdated") { $order = "updated_on"; } $order_dir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'webpages')); $succ = 0; $err = 0; foreach ($ids as $id) { $web_page = ProjectWebpages::findById($id); if (isset($web_page) && $web_page->canDelete(logged_user())) { try { DB::beginWork(); $web_page->trash(); ApplicationLogs::createLog($web_page, ApplicationLogs::ACTION_TRASH); DB::commit(); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success delete objects", $succ)); } if ($err > 0) { flash_error(lang("error delete objects", $err)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $webpage = ProjectWebpages::findById($id); try { $webpage->setIsRead(logged_user()->getId(), true); $succ++; } catch (Exception $e) { $err++; } } if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $webpage = ProjectWebpages::findById($id); try { $webpage->setIsRead(logged_user()->getId(), false); $succ++; } catch (Exception $e) { $err++; } } if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'webpages')); $succ = 0; $err = 0; foreach ($ids as $id) { $web_page = ProjectWebpages::findById($id); if (isset($web_page) && $web_page->canEdit(logged_user())) { try { DB::beginWork(); $web_page->archive(); ApplicationLogs::createLog($web_page, ApplicationLogs::ACTION_ARCHIVE); DB::commit(); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } if ($err > 0) { flash_error(lang("error archive objects", $err)); } } } } } $res = ProjectWebpages::instance()->listing(array("order" => $order, "order_dir" => $order_dir)); $object = array("totalCount" => $res->total, "start" => $start, "webpages" => array()); if (isset($res->objects)) { $index = 0; $ids = array(); foreach ($res->objects as $w) { $ids[] = $w->getId(); $object["webpages"][] = array("ix" => $index++, "id" => $w->getId(), "object_id" => $w->getObjectId(), "ot_id" => $w->getObjectTypeId(), "name" => $w->getObjectName(), "description" => $w->getDescription(), "url" => $w->getUrl(), "updatedOn" => $w->getUpdatedOn() instanceof DateTimeValue ? $w->getUpdatedOn()->isToday() ? format_time($w->getUpdatedOn()) : format_datetime($w->getUpdatedOn()) : '', "updatedOn_today" => $w->getUpdatedOn() instanceof DateTimeValue ? $w->getUpdatedOn()->isToday() : 0, "updatedBy" => $w->getUpdatedByDisplayName(), "updatedById" => $w->getUpdatedById(), "memPath" => json_encode($w->getMembersToDisplayPath())); } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach ($object["webpages"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } } ajx_extra_data($object); }
/** * Used for Drag & Drop, adds objects to a member * @author alvaro */ function add_objects_to_member() { $ids = json_decode(array_var($_POST, 'objects')); $mem_id = array_var($_POST, 'member'); if (!is_array($ids) || count($ids) == 0) { ajx_current("empty"); return; } $member = Members::findById($mem_id); try { DB::beginWork(); $objects = array(); $from = array(); foreach ($ids as $oid) { /* @var $obj ContentDataObject */ $obj = Objects::findObject($oid); $dim_obj_type_content = DimensionObjectTypeContents::findOne(array('conditions' => array('`dimension_id`=? AND `dimension_object_type_id`=? AND `content_object_type_id`=?', $member->getDimensionId(), $member->getObjectTypeId(), $obj->getObjectTypeId()))); if (!$dim_obj_type_content instanceof DimensionObjectTypeContent) { continue; } if (!$dim_obj_type_content->getIsMultiple() || array_var($_POST, 'remove_prev')) { $db_res = DB::execute("SELECT group_concat(om.member_id) as old_members FROM " . TABLE_PREFIX . "object_members om INNER JOIN " . TABLE_PREFIX . "members m ON om.member_id=m.id WHERE m.dimension_id=" . $member->getDimensionId() . " AND om.object_id=" . $obj->getId()); $row = $db_res->fetchRow(); if (array_var($row, 'old_members') != "") { $from[$obj->getId()] = $row['old_members']; } // remove from previous members ObjectMembers::delete('`object_id` = ' . $obj->getId() . ' AND `member_id` IN (SELECT `m`.`id` FROM `' . TABLE_PREFIX . 'members` `m` WHERE `m`.`dimension_id` = ' . $member->getDimensionId() . ')'); } $obj->addToMembers(array($member)); $obj->addToSharingTable(); $objects[] = $obj; } DB::commit(); // add to application logs foreach ($objects as $object) { $action = array_var($from, $obj->getId()) ? ApplicationLogs::ACTION_MOVE : ApplicationLogs::ACTION_COPY; $log_data = (array_var($from, $obj->getId()) ? "from:" . array_var($from, $obj->getId()) . ";" : "") . "to:" . $member->getId(); ApplicationLogs::instance()->createLog($object, $action, false, true, true, $log_data); } $lang_key = count($ids) > 1 ? 'objects moved to member success' : 'object moved to member success'; flash_success(lang($lang_key, $member->getName())); if (array_var($_POST, 'reload')) { ajx_current('reload'); } else { ajx_current('empty'); } } catch (Exception $e) { DB::rollback(); ajx_current("empty"); flash_error(lang('unable to move objects')); } }
/** * Delete project * * @param void * @return null */ function delete() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $pid = get_id(); $u = Users::findOne(array("conditions" => "personal_project_id = {$pid}")); if ($u) { //flash_error("id: $pid, u: ".$u->getId()); ajx_current("empty"); flash_error(lang('cannot delete personal project')); return; //$this->redirectTo('administration', 'projects'); } $project = Projects::findById(get_id()); if (!$project instanceof Project) { flash_error(lang('project dnx')); ajx_current("empty"); return; //$this->redirectTo('administration', 'projects'); } // if if (!$project->canDelete(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; //$this->redirectToReferer(get_url('administration', 'projects')); } // if if (!array_var($_GET, 'confirm')) { tpl_assign('project', $project); $this->setTemplate('pre_delete'); return; } ajx_current("empty"); try { $id = $project->getId(); $name = $project->getName(); DB::beginWork(); $project->delete(); CompanyWebsite::instance()->setProject(null); ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_DELETE); DB::commit(); flash_success(lang('success delete project', $project->getName())); evt_add("workspace deleted", array("id" => $id, "name" => $name)); ajx_current("start"); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } // try //$this->redirectTo('administration', 'projects'); }
/** * Delete company logo * * @param void * @return null */ function delete_logo() { if(!logged_user()->isAdministrator()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $company = Contacts::findById(get_id()); if(!($company instanceof Contact)) { flash_error(lang('company dnx')); ajx_current("empty"); return; } // if try { DB::beginWork(); $company->deleteLogo(); $company->save(); ApplicationLogs::createLog($company, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success delete company logo')); ajx_current("back"); } catch(Exception $e) { DB::rollback(); flash_error(lang('error delete company logo')); ajx_current("empty"); } // try } // delete_logo
/** * Delete avatar * * @param void * @return null */ function delete_avatar() { $user = Users::findById(get_id()); if (!$user instanceof User) { flash_error(lang('user dnx')); $this->redirectTo('dashboard'); } // if if (!$user->canUpdateProfile(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo('dashboard'); } // if $redirect_to = array_var($_GET, 'redirect_to'); if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) { $redirect_to = $user->getUpdateAvatarUrl(); } // if tpl_assign('redirect_to', $redirect_to); if (!$user->hasAvatar()) { flash_error(lang('avatar dnx')); $this->redirectToUrl($redirect_to); } // if try { DB::beginWork(); $user->deleteAvatar(); $user->save(); ApplicationLogs::createLog($user, null, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success delete avatar')); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete avatar')); } // try $this->redirectToUrl($redirect_to); }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'ApplicationLogs')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ApplicationLogs::instance()->paginate($arguments, $items_per_page, $current_page); //$instance =& ApplicationLogs::instance(); //return $instance->paginate($arguments, $items_per_page, $current_page); } // if }
function unarchive() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $object_id = get_id('object_id'); $object = Objects::findObject($object_id); if ($object instanceof ApplicationDataObject && $object->canEdit(logged_user())) { try { DB::beginWork(); $object->unarchive(); ApplicationLogs::createLog($object, ApplicationLogs::ACTION_UNARCHIVE); DB::commit(); flash_success(lang("success unarchive objects", 1)); if ($object instanceof Contact) { self::reloadPersonsDimension(); } } catch (Exception $e) { DB::rollback(); flash_error(lang("error unarchive objects", 1)); } } else { flash_error(lang("no access permissions")); } ajx_current("back"); }
/** * Open specific milestone * * @access public * @param void * @return null */ function open() { $milestone = ProjectMilestones::findById(get_id()); if (!$milestone instanceof ProjectMilestone) { flash_error(lang('milestone dnx')); $this->redirectTo('milestone'); } // if if (!$milestone->canChangeStatus(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('milestone')); } // if try { $milestone->setCompletedOn(null); $milestone->setCompletedById(0); DB::beginWork(); $milestone->save(); ApplicationLogs::createLog($milestone, active_project(), ApplicationLogs::ACTION_OPEN); DB::commit(); flash_success(lang('success open milestone', $milestone->getName())); } catch (Exception $e) { DB::rollback(); flash_error(lang('error open milestone')); } // try $this->redirectToReferer($milestone->getViewUrl()); }
/** * Delete selected revision (if you have proper permissions) * * @param void * @return null */ function delete_revision() { $this->setTemplate('del_revision'); $revision = ProjectFileRevisions::findById(get_id()); if (!$revision instanceof ProjectFileRevision) { flash_error(lang('file revision dnx')); $this->redirectToReferer(get_url('files')); } // if $file = $revision->getFile(); if (!$file instanceof ProjectFile) { flash_error(lang('file dnx')); $this->redirectToReferer(get_url('files')); } // if $all_revisions = $file->getRevisions(); if (count($all_revisions) == 1) { flash_error(lang('cant delete only revision')); $this->redirectToReferer($file->getDetailsUrl()); } // if if (!$revision->canDelete(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('files')); } // if $delete_data = array_var($_POST, 'deleteFileRevision'); tpl_assign('file', $file); tpl_assign('revision', $revision); tpl_assign('delete_data', $delete_data); if (!is_array($delete_data)) { $delete_data = array('really' => 0, 'password' => ''); // array tpl_assign('delete_data', $delete_data); } else { if ($delete_data['really'] == 1) { $password = $delete_data['password']; if (trim($password) == '') { tpl_assign('error', new Error(lang('password value missing'))); return $this->render(); } if (!logged_user()->isValidPassword($password)) { tpl_assign('error', new Error(lang('invalid login data'))); return $this->render(); } try { DB::beginWork(); $revision->delete(); ApplicationLogs::createLog($revision, $revision->getProject(), ApplicationLogs::ACTION_DELETE); DB::commit(); flash_success(lang('success delete file revision')); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete file revision')); } // try $this->redirectToUrl($file->getDetailsUrl()); } else { flash_error(lang('error delete file revision')); $this->redirectToUrl($file->getDetailsUrl()); } } }
/** * Clear application logs for this project * * @param void * @return null */ function clearLogs() { ApplicationLogs::clearByProject($this); }
/** * Delete specific category * * @access public * @param void * @return null */ function delete_category() { $category = ProjectCategories::findById(get_id()); if (!$category instanceof ProjectCategory) { flash_error(lang('category dnx')); $this->redirectTo('tickets', 'categories'); } // if if (!$category->canDelete(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('tickets', 'categories')); } // if try { DB::beginWork(); $category->delete(); ApplicationLogs::createLog($category, $category->getProject(), ApplicationLogs::ACTION_DELETE); DB::commit(); flash_success(lang('success deleted category', $category->getName())); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete category')); } // try $this->redirectTo('tickets', 'categories'); }
/** * Delete locale logo * * @param void * @return null */ function delete_logo() { $locale = I18nLocales::findById(get_id()); if (!$locale instanceof I18nLocale) { flash_error(lang('locale dnx')); $this->redirectToReferer(get_url('i18n', 'index')); } // if if (!$locale->canEdit(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo('i18n', 'index'); } // if try { DB::beginWork(); $locale->deleteLogo(); $locale->save(); ApplicationLogs::createLog($locale, 0, ApplicationLogs::ACTION_EDIT); DB::commit(); flash_success(lang('success delete logo')); } catch (Exception $e) { DB::rollback(); flash_error(lang('error delete logo', $e)); } // try $this->redirectToUrl($locale->getEditLogoUrl()); }
/** * Edit a wiki page * * @return void */ function edit() { if (!WikiPage::canEdit(logged_user())) { flash_error(lang('no wiki page edit permissions')); $this->redirectToReferer(get_url('wiki')); } //Get the page from the url params $page = Wiki::getPageById(get_id(), active_project()); if (!instance_of($page, 'WikiPage')) { //If the page doesn't exist, redirect to wiki index flash_error(lang('wiki page dnx')); $this->redirectToReferer(get_url('wiki')); } // if //Check that the user can edit this entry if (!$page->canEdit(logged_user())) { flash_error(lang('no access permissions')); $this->redirectTo(get_url('wiki')); } // if // Check that the page isn't locked if ($page->isLocked() && !$page->canUnlock(logged_user())) { flash_error(lang('wiki page locked by', $page->getLockedByUser()->getUsername())); $this->redirectToUrl($page->getViewUrl()); } // if //Here we will edit a wiki page $preview = false; $data = array_var($_POST, 'wiki', false); if (false !== $data) { $preview = array_key_exists('preview', $data); } if (!$preview && $data) { //if(null !== ($data = array_var($_POST, 'wiki'))){ //If we have received data //Make a new revision $revision = $page->makeRevision(); $revision->setFromAttributes($data); $page->setProjectIndex($data['project_index']); $page->setProjectSidebar($data['project_sidebar']); $page->setPublish($data['publish']); $page->setParentId($data['parent_id']); // Check to see if we want to lock this page if (isset($data['locked'])) { if ($data['locked'] == 1 && $page->canLock(logged_user()) && !$page->isLocked()) { // If we want to lock this page and the user has permissions to lock it, and the page is not already locked $page->setLocked(true); $page->setLockedById(logged_user()->getId()); $page->setLockedOn(DateTimeValueLib::now()); } elseif ($data['locked'] == 0 & $page->canUnlock(logged_user()) && $page->isLocked()) { // Else if we want to unlock the page, and the user is allowed to, and the page is locked $page->setLocked(false); } // if } // if //Set the users ID $revision->setCreatedById(logged_user()->getId()); try { //Start the transaction DB::beginWork(); //Save the page and create revision //The page will make sure that the revision's project and page Id are correct $page->save(); ApplicationLogs::createLog($page, active_project(), ApplicationLogs::ACTION_EDIT); if (plugin_active('tags')) { //Set the tags $page->setTagsFromCSV($data['tags']); } //Commit changes DB::commit(); flash_success(lang('success edit wiki page')); //Redirect to the page we just created $this->redirectToUrl($page->getViewUrl()); } catch (Exception $e) { //Get rid of any Db changes we've made DB::rollback(); //Assign the problem to the template so we can tell the user tpl_assign('error', $e); } //try } else { if (array_var($_GET, 'revision')) { //If we want to make a new revision based off a revision $revision = $page->getRevision($_GET['revision']); } else { $revision = $page->getLatestRevision(); } } //if if (!$data) { // there was no input POSTed $data['content'] = $revision->getContent(); } $data['preview_content'] = do_textile($data['content']); //Assign revision object tpl_assign('revision', $revision); tpl_assign('data', $data); //Assign the page object tpl_assign('page', $page); $tag_names = plugin_active('tags') ? $page->getTagNames() : ''; $tags = is_array($tag_names) ? implode(', ', $tag_names) : ''; tpl_assign('tags', $tags); //Set the template $this->setTemplate('edit'); $this->setSidebar(get_template_path('textile_help_sidebar')); }