コード例 #1
0
 /**
  * Edit task
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_task()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_task');
     $task = ProjectTasks::findById(get_id());
     if (!$task instanceof ProjectTask) {
         flash_error(lang('task list dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$task->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $task_data = array_var($_POST, 'task');
     if (!is_array($task_data)) {
         $this->getRepeatOptions($task, $occ, $rsel1, $rsel2, $rsel3, $rnum, $rend, $rjump);
         $tag_names = $task->getTagNames();
         $task_data = array('title' => array_var($_POST, 'title', $task->getTitle()), 'text' => $task->getText(), 'milestone_id' => array_var($_POST, 'milestone_id', $task->getMilestoneId()), 'due_date' => getDateValue(array_var($_POST, 'task_due_date'), $task->getDueDate()), 'start_date' => getDateValue(array_var($_POST, 'task_start_date', $task->getStartDate())), 'parent_id' => $task->getParentId(), 'project_id' => array_var($_POST, 'project_id', $task->getProjectId()), 'tags' => is_array($tag_names) && count($tag_names) ? implode(', ', $tag_names) : '', 'is_private' => $task->isPrivate(), 'assigned_to' => array_var($_POST, 'assigned_to', $task->getAssignedToCompanyId() . ':' . $task->getAssignedToUserId()), 'priority' => array_var($_POST, 'priority', $task->getPriority()), 'send_notification' => array_var($_POST, 'notify') == 'true', 'time_estimate' => $task->getTimeEstimate(), 'forever' => $task->getRepeatForever(), 'rend' => $rend, 'rnum' => $rnum, 'rjump' => $rjump, 'rsel1' => $rsel1, 'rsel2' => $rsel2, 'rsel3' => $rsel3, 'occ' => $occ, 'repeat_by' => $task->getRepeatBy(), 'object_subtype' => array_var($_POST, "object_subtype", $task->getObjectSubtype() != 0 ? $task->getObjectSubtype() : config_option('default task co type')));
         // array
         $handins = ObjectHandins::getAllHandinsByObject($task);
         $id = 0;
         if ($handins) {
             foreach ($handins as $handin) {
                 $task_data['handin' . $id] = array('title' => $handin->getTitle(), 'assigned_to' => $handin->getResponsibleCompanyId() . ':' . $handin->getResponsibleUserId());
                 // array
                 $id = $id + 1;
                 if ($id > 3) {
                     break;
                 }
             }
             // foreach
         }
         // if
     }
     // if
     tpl_assign('task', $task);
     tpl_assign('task_data', $task_data);
     if (is_array(array_var($_POST, 'task'))) {
         //MANAGE CONCURRENCE WHILE EDITING
         $upd = array_var($_POST, 'updatedon');
         if ($upd && $task->getUpdatedOn()->getTimestamp() > $upd && !array_var($_POST, 'merge-changes') == 'true') {
             ajx_current('empty');
             evt_add("handle edit concurrence", array("updatedon" => $task->getUpdatedOn()->getTimestamp(), "genid" => array_var($_POST, 'genid')));
             return;
         }
         if (array_var($_POST, 'merge-changes') == 'true') {
             $this->setTemplate('view_list');
             $edited_task = ProjectTasks::findById($task->getId());
             ajx_set_no_toolbar(true);
             ajx_set_panel(lang('tab name', array('name' => $edited_task->getTitle())));
             tpl_assign('task_list', $edited_task);
             ajx_extra_data(array("title" => $edited_task->getTitle(), 'icon' => 'ico-task'));
             return;
         }
         $old_owner = $task->getAssignedTo();
         if (array_var($task_data, 'parent_id') == $task->getId()) {
             flash_error(lang("task own parent error"));
             ajx_current("empty");
             return;
         }
         $old_is_private = $task->isPrivate();
         $old_project_id = $task->getProjectId();
         $project_id = array_var($_POST, 'ws_ids', 0);
         if ($old_project_id != $project_id) {
             $newProject = Projects::findById($project_id);
             if (!$newProject instanceof Project || !$task->canAdd(logged_user(), $newProject)) {
                 flash_error(lang('no access permissions'));
                 ajx_current("empty");
                 return;
             }
         }
         $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date'));
         $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date'));
         try {
             $err_msg = $this->setRepeatOptions($task_data);
             if ($err_msg) {
                 flash_error($err_msg);
                 ajx_current("empty");
                 return;
             }
             if (!isset($task_data['parent_id'])) {
                 $task_data['parent_id'] = 0;
             }
             $was_template = $task->getIsTemplate();
             $task->setFromAttributes($task_data);
             $task->setIsTemplate($was_template);
             // is_template value must not be changed from ui
             // Set assigned to
             $assigned_to = explode(':', array_var($task_data, 'assigned_to', ''));
             $company_id = array_var($assigned_to, 0, 0);
             $user_id = array_var($assigned_to, 1, 0);
             $can_assign = can_assign_task_to_company_user(logged_user(), $task, $company_id, $user_id);
             if ($can_assign !== true) {
                 flash_error($can_assign);
                 return;
             }
             $task->setAssignedToCompanyId($company_id);
             $task->setAssignedToUserId($user_id);
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $task->setIsPrivate($old_is_private);
             }
             $totalMinutes = array_var($task_data, 'time_estimate_hours') * 60 + array_var($task_data, 'time_estimate_minutes');
             $task->setTimeEstimate($totalMinutes);
             //Add handins
             $handins = array();
             for ($i = 0; $i < 4; $i++) {
                 if (isset($task_data["handin{$i}"]) && is_array($task_data["handin{$i}"]) && trim(array_var($task_data["handin{$i}"], 'title')) != '') {
                     $assigned_to = explode(':', array_var($task_data["handin{$i}"], 'assigned_to', ''));
                     $handins[] = array('title' => array_var($task_data["handin{$i}"], 'title'), 'responsible_company_id' => array_var($assigned_to, 0, 0), 'responsible_user_id' => array_var($assigned_to, 1, 0));
                     // array
                 }
                 // if
             }
             // for
             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->setTagsFromCSV(array_var($task_data, 'tags'));
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($task, !$task->getIsTemplate());
             $object_controller->link_to_new_object($task);
             $object_controller->add_subscribers($task);
             $object_controller->add_custom_properties($task);
             $object_controller->add_reminders($task);
             // apply values to subtasks
             $subtasks = $task->getAllSubTasks();
             $project = $task->getProject();
             $milestone_id = $task->getMilestoneId();
             $apply_ws = array_var($task_data, 'apply_ws_subtasks') == "checked";
             $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->getAssignedTo() instanceof ApplicationDataObject) {
                     $sub->setAssignedToCompanyId($company_id);
                     $sub->setAssignedToUserId($user_id);
                     $modified = true;
                 }
                 if ($apply_ws) {
                     $sub->setProject($project);
                     $modified = true;
                 }
                 if ($apply_ms) {
                     $sub->setMilestoneId($milestone_id);
                     $modified = true;
                 }
                 if ($modified) {
                     $sub->save();
                 }
             }
             $task->resetIsRead();
             ApplicationLogs::createLog($task, $task->getWorkspaces(), ApplicationLogs::ACTION_EDIT);
             DB::commit();
             try {
                 if (array_var($task_data, 'send_notification') == 'checked') {
                     $new_owner = $task->getAssignedTo();
                     if ($new_owner instanceof User) {
                         Notifier::taskAssigned($task);
                     }
                     // if
                 }
                 // if
             } catch (Exception $e) {
             }
             // try
             flash_success(lang('success edit task list', $task->getTitle()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #2
0
 /**
  * Show and process edit milestone form
  *
  * @access public
  * @param void
  * @return null
  */
 function edit()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_milestone');
     $milestone = ProjectMilestones::findById(get_id());
     if (!$milestone instanceof ProjectMilestone) {
         flash_error(lang('milestone dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$milestone->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $milestone_data = array_var($_POST, 'milestone');
     if (!is_array($milestone_data)) {
         $tag_names = $milestone->getTagNames();
         $milestone_data = array('name' => $milestone->getName(), 'due_date' => $milestone->getDueDate(), 'description' => $milestone->getDescription(), 'assigned_to' => $milestone->getAssignedToCompanyId() . ':' . $milestone->getAssignedToUserId(), 'tags' => is_array($tag_names) ? implode(', ', $tag_names) : '', 'is_private' => $milestone->isPrivate(), 'is_urgent' => $milestone->getIsUrgent());
         // array
     }
     // if
     tpl_assign('milestone_data', $milestone_data);
     tpl_assign('milestone', $milestone);
     if (is_array(array_var($_POST, 'milestone'))) {
         if (array_var($milestone_data, 'due_date_value') != '') {
             $milestone_data['due_date'] = getDateValue(array_var($milestone_data, 'due_date_value'));
         } else {
             $now = DateTimeValueLib::now();
             $milestone_data['due_date'] = DateTimeValueLib::make(0, 0, 0, $now->getMonth(), $now->getDay(), $now->getYear());
         }
         $old_owner = $milestone->getAssignedTo();
         // remember the old owner
         $assigned_to = explode(':', array_var($milestone_data, 'assigned_to', ''));
         $old_is_private = $milestone->isPrivate();
         $milestone->setFromAttributes($milestone_data);
         $urgent = array_var($milestone_data, 'is_urgent') == 'checked';
         $milestone->setIsUrgent($urgent);
         if (!logged_user()->isMemberOfOwnerCompany()) {
             $milestone->setIsPrivate($old_is_private);
         }
         $old_project_id = $milestone->getProjectId();
         $project_id = array_var($_POST, 'ws_ids');
         if ($old_project_id != $project_id) {
             $newProject = Projects::findById($project_id);
             if (!$milestone->canAdd(logged_user(), $newProject)) {
                 flash_error(lang('no access permissions'));
                 ajx_current("empty");
                 return;
             }
             // if
             $milestone->move_inconsistent_tasks($newProject);
         }
         $milestone->setAssignedToCompanyId(array_var($assigned_to, 0, 0));
         $milestone->setAssignedToUserId(array_var($assigned_to, 1, 0));
         try {
             DB::beginWork();
             $milestone->save();
             $milestone->setTagsFromCSV(array_var($milestone_data, 'tags'));
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($milestone);
             $object_controller->link_to_new_object($milestone);
             $object_controller->add_subscribers($milestone);
             $object_controller->add_custom_properties($milestone);
             $object_controller->add_reminders($milestone);
             ApplicationLogs::createLog($milestone, $milestone->getWorkspaces(), ApplicationLogs::ACTION_EDIT);
             DB::commit();
             // If owner is changed send notification but don't break submission
             try {
                 $new_owner = $milestone->getAssignedTo();
                 if (array_var($milestone_data, 'send_notification') == 'checked') {
                     if ($old_owner instanceof User) {
                         // We have a new owner and it is different than old owner
                         if ($new_owner instanceof User && $new_owner->getId() != $old_owner->getId()) {
                             Notifier::milestoneAssigned($milestone);
                         }
                     } else {
                         // We have new owner
                         if ($new_owner instanceof User) {
                             Notifier::milestoneAssigned($milestone);
                         }
                     }
                     // if
                 }
                 // if
             } catch (Exception $e) {
             }
             // try
             flash_success(lang('success edit milestone', $milestone->getName()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #3
0
	/**
	 * Show and process edit milestone form
	 *
	 * @access public
	 * @param void
	 * @return null
	 */
	function edit() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		$this->setTemplate('add_milestone');

		$milestone = ProjectMilestones::findById(get_id());
		if(!($milestone instanceof ProjectMilestone)) {
			flash_error(lang('milestone dnx'));
			ajx_current("empty");
			return;
		} // if

		if(!$milestone->canEdit(logged_user())) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}

		$milestone_data = array_var($_POST, 'milestone');
		if(!is_array($milestone_data)) {
			$milestone_data = array(
	          'name'        => $milestone->getObjectName(),
	          'due_date'    => $milestone->getDueDate(),
	          'description' => $milestone->getDescription(),
	          'is_urgent' 	=> $milestone->getIsUrgent()
			); // array
		} // if

		tpl_assign('milestone_data', $milestone_data);
		tpl_assign('milestone', $milestone);

		if(is_array(array_var($_POST, 'milestone'))) {
			if (array_var($milestone_data, 'due_date_value') != ''){
				$milestone_data['due_date'] = getDateValue(array_var($milestone_data, 'due_date_value'));
			} else {
				$now = DateTimeValueLib::now();
				$milestone_data['due_date'] = DateTimeValueLib::make(0, 0, 0, $now->getMonth(), $now->getDay(), $now->getYear());
			}
			
			$milestone->setFromAttributes($milestone_data);
			$urgent = array_var($milestone_data, 'is_urgent') == 'checked';
			$milestone->setIsUrgent($urgent);

			try {
				$member_ids = json_decode(array_var($_POST, 'members'));
				
				DB::beginWork();
				$milestone->save();
				
				$object_controller = new ObjectController();
				$object_controller->add_to_members($milestone, $member_ids);
			    $object_controller->add_subscribers($milestone);
			    $object_controller->link_to_new_object($milestone);
				$object_controller->add_custom_properties($milestone);
				$object_controller->add_reminders($milestone);
			    
				ApplicationLogs::createLog($milestone, ApplicationLogs::ACTION_EDIT);
				DB::commit();

				flash_success(lang('success edit milestone', $milestone->getObjectName()));
				ajx_current("back");

			} catch(Exception $e) {
				DB::rollback();
				flash_error($e->getMessage());
				ajx_current("empty");
			} // try
		} // if
	} // edit
コード例 #4
0
        function repetitive_event_related_edit($event,$data){
            // run the query to set the event data
            $event->setFromAttributes($data);

            $this->registerInvitations($data, $event, false);
            if (isset($data['confirmAttendance'])) {
                $this->change_invitation_state($data['confirmAttendance'], $event->getId(), $user_filter);
            }
            DB::beginWork();
            $event->save();  

            if($event->getSpecialID() != ""){
                $this->sync_calendar_extern($event);
            }

            $object_controller = new ObjectController();
            $object_controller->add_to_members($event, array_var($task_data, 'members'));
            $object_controller->add_subscribers($event);

            $object_controller->link_to_new_object($event);
            $object_controller->add_custom_properties($event);
            $object_controller->add_reminders($event);

            $event->resetIsRead();

            ApplicationLogs::createLog($event, ApplicationLogs::ACTION_EDIT);
        }
コード例 #5
0
 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();
 }
コード例 #6
0
 function cloneTask($copy_status = false)
 {
     $new_task = new ProjectTask();
     $new_task->setParentId($this->getParentId());
     $new_task->setTitle($this->getTitle());
     $new_task->setText($this->getText());
     $new_task->setAssignedToCompanyId($this->getAssignedToCompanyId());
     $new_task->setAssignedToUserId($this->getAssignedToUserId());
     $new_task->setAssignedOn($this->getAssignedOn());
     $new_task->setAssignedById($this->getAssignedById());
     $new_task->setTimeEstimate($this->getTimeEstimate());
     $new_task->setStartedOn($this->getStartedOn());
     $new_task->setStartedById($this->getStartedById());
     $new_task->setPriority($this->getPriority());
     $new_task->setState($this->getState());
     $new_task->setOrder($this->getOrder());
     $new_task->setMilestoneId($this->getMilestoneId());
     $new_task->setIsPrivate($this->getIsPrivate());
     $new_task->setIsTemplate($this->getIsTemplate());
     $new_task->setFromTemplateId($this->getFromTemplateId());
     if ($this->getDueDate() instanceof DateTimeValue) {
         $new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
     }
     if ($this->getStartDate() instanceof DateTimeValue) {
         $new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
     }
     if ($copy_status) {
         $new_task->setCompletedById($this->getCompletedById());
         $new_task->setCompletedOn($this->getCompletedOn());
     }
     $new_task->save();
     $new_task->setTagsFromCSV(implode(",", $this->getTagNames()));
     foreach ($this->getWorkspaces() as $ws) {
         $new_task->addToWorkspace($ws);
     }
     if (is_array($this->getAllLinkedObjects())) {
         foreach ($this->getAllLinkedObjects() as $lo) {
             $new_task->linkObject($lo);
         }
     }
     $sub_tasks = $this->getAllSubTasks();
     foreach ($sub_tasks as $st) {
         if ($st->getParentId() == $this->getId()) {
             $new_st = $st->cloneTask($copy_status);
             if ($copy_status) {
                 $new_st->setCompletedById($st->getCompletedById());
                 $new_st->setCompletedOn($st->getCompletedOn());
                 $new_st->save();
             }
             $new_task->attachTask($new_st);
         }
     }
     foreach ($this->getAllComments() as $com) {
         $new_com = new Comment();
         $new_com->setAuthorEmail($com->getAuthorEmail());
         $new_com->setAuthorName($com->getAuthorName());
         $new_com->setAuthorHomepage($com->getAuthorHomepage());
         $new_com->setCreatedById($com->getCreatedById());
         $new_com->setCreatedOn($com->getCreatedOn());
         $new_com->setUpdatedById($com->getUpdatedById());
         $new_com->setUpdatedOn($com->getUpdatedOn());
         $new_com->setIsAnonymous($com->getIsAnonymous());
         $new_com->setIsPrivate($com->getIsPrivate());
         $new_com->setText($com->getText());
         $new_com->setRelObjectId($new_task->getId());
         $new_com->setRelObjectManager("ProjectTasks");
         $new_com->save();
     }
     $_POST['subscribers'] = array();
     foreach ($this->getSubscribers() as $sub) {
         $_POST['subscribers']["user_" . $sub->getId()] = "checked";
     }
     $obj_controller = new ObjectController();
     $obj_controller->add_subscribers($new_task);
     foreach ($this->getCustomProperties() as $prop) {
         $new_prop = new ObjectProperty();
         $new_prop->setRelObjectId($new_task->getId());
         $new_prop->setRelObjectManager($prop->getRelObjectManager());
         $new_prop->setPropertyName($prop->getPropertyName());
         $new_prop->setPropertyValue($prop->getPropertyValue());
         $new_prop->save();
     }
     $custom_props = CustomProperties::getAllCustomPropertiesByObjectType("ProjectTasks");
     foreach ($custom_props as $c_prop) {
         $values = CustomPropertyValues::getCustomPropertyValues($this->getId(), $c_prop->getId());
         if (is_array($values)) {
             foreach ($values as $val) {
                 $cp = new CustomPropertyValue();
                 $cp->setObjectId($new_task->getId());
                 $cp->setCustomPropertyId($val->getCustomPropertyId());
                 $cp->setValue($val->getValue());
                 $cp->save();
             }
         }
     }
     $reminders = ObjectReminders::getByObject($this);
     foreach ($reminders as $reminder) {
         $copy_reminder = new ObjectReminder();
         $copy_reminder->setContext($reminder->getContext());
         $reminder_date = $new_task->getColumnValue($reminder->getContext());
         if ($reminder_date instanceof DateTimeValue) {
             $reminder_date = new DateTimeValue($reminder_date->getTimestamp());
             $reminder_date->add('m', -$reminder->getMinutesBefore());
         }
         $copy_reminder->setDate($reminder_date);
         $copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
         $copy_reminder->setObject($new_task);
         $copy_reminder->setType($reminder->getType());
         $copy_reminder->setUserId($reminder->getUserId());
         $copy_reminder->save();
     }
     return $new_task;
 }
コード例 #7
0
 function icalendar_import()
 {
     @set_time_limit(0);
     if (isset($_GET['from_menu']) && $_GET['from_menu'] == 1) {
         unset($_SESSION['history_back']);
     }
     if (isset($_SESSION['history_back'])) {
         if ($_SESSION['history_back'] > 0) {
             $_SESSION['history_back'] = $_SESSION['history_back'] - 1;
         }
         if ($_SESSION['history_back'] == 0) {
             unset($_SESSION['history_back']);
         }
         ajx_current("back");
     } else {
         $ok = false;
         $this->setTemplate('cal_import');
         $filedata = array_var($_FILES, 'cal_file');
         if (is_array($filedata)) {
             $filename = $filedata['tmp_name'] . 'vcal';
             copy($filedata['tmp_name'], $filename);
             $events_data = CalFormatUtilities::decode_ical_file($filename);
             if (count($events_data)) {
                 try {
                     DB::beginWork();
                     foreach ($events_data as $ev_data) {
                         $event = new ProjectEvent();
                         $project = active_or_personal_project();
                         if ($ev_data['subject'] == '') {
                             $ev_data['subject'] = lang('no subject');
                         }
                         $event->setFromAttributes($ev_data);
                         $event->save();
                         $event->addToWorkspace($project);
                         $object_controller = new ObjectController();
                         $object_controller->add_subscribers($event);
                         ApplicationLogs::createLog($event, null, ApplicationLogs::ACTION_ADD);
                         $this->registerInvitations($ev_data, $event);
                         if (isset($ev_data['confirmAttendance'])) {
                             if ($event->getCreatedBy() instanceof User) {
                                 $this->change_invitation_state($ev_data['confirmAttendance'], $event->getId(), $event->getCreatedBy()->getId());
                             }
                         }
                     }
                     DB::commit();
                     $ok = true;
                     flash_success(lang('success import events', count($events_data)));
                     $_SESSION['history_back'] = 1;
                 } catch (Exception $e) {
                     DB::rollback();
                     flash_error($e->getMessage());
                 }
             } else {
                 flash_error(lang('no events to import'));
             }
             unset($filename);
             if (!$ok) {
                 ajx_current("empty");
             }
         } else {
             if (array_var($_POST, 'atimportform', 0)) {
                 ajx_current("empty");
             }
         }
     }
 }
コード例 #8
0
 /**
  * Edit specific message
  *
  * @access public
  * @param void
  * @return null
  */
 function edit()
 {
     $this->setTemplate('add_message');
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current('empty');
         return;
     }
     $message = ProjectMessages::findById(get_id());
     if (!$message instanceof ProjectMessage) {
         flash_error(lang('message dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$message->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $message_data = array_var($_POST, 'message');
     if (!is_array($message_data)) {
         $message_data = array('name' => $message->getObjectName(), 'text' => $message->getText(), 'type_content' => $message->getTypeContent());
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
     }
     // if
     tpl_assign('message', $message);
     tpl_assign('message_data', $message_data);
     if (is_array(array_var($_POST, 'message'))) {
         foreach ($message_data as $k => &$v) {
             $v = remove_scripts($v);
         }
         try {
             //MANAGE CONCURRENCE WHILE EDITING
             /* FIXME or REMOVEME
             			$upd = array_var($_POST, 'updatedon');
             			if ($upd && $message->getUpdatedOn()->getTimestamp() > $upd && !array_var($_POST,'merge-changes') == 'true')
             			{
             				ajx_current('empty');
             				evt_add("handle edit concurrence", array(
             					"updatedon" => $message->getUpdatedOn()->getTimestamp(),
             					"genid" => array_var($_POST,'genid')
             				));
             				return;
             			}
             			if (array_var($_POST,'merge-changes') == 'true')
             			{
             				$this->setTemplate('view');
             				$edited_note = ProjectMessages::findById($message->getId());
             				tpl_assign('message', $edited_note);
             				tpl_assign('subscribers', $edited_note->getSubscribers());
             				ajx_extra_data(array("name" => $edited_note->getObjectName(), 'icon'=>'ico-message'));
             				ajx_set_no_toolbar(true);
             				ajx_set_panel(lang ('tab name',array('name'=>$edited_note->getObjectName())));					
             				return;
             			}
             			*/
             if (config_option("wysiwyg_messages")) {
                 $message_data['type_content'] = "html";
                 $message_data['text'] = preg_replace("/[\n|\r|\n\r]/", '', array_var($message_data, 'text'));
             } else {
                 $message_data['type_content'] = "text";
             }
             $message->setFromAttributes($message_data);
             DB::beginWork();
             $message->save();
             $object_controller = new ObjectController();
             $member_ids = json_decode(array_var($_POST, 'members'));
             $object_controller->add_to_members($message, $member_ids);
             $object_controller->link_to_new_object($message);
             $object_controller->add_subscribers($message);
             $object_controller->add_custom_properties($message);
             $message->resetIsRead();
             DB::commit();
             ApplicationLogs::createLog($message, ApplicationLogs::ACTION_EDIT);
             flash_success(lang('success edit message', $message->getObjectName()));
             if (array_var($_POST, 'popup', false)) {
                 ajx_current("reload");
             } else {
                 ajx_current("back");
             }
             if (array_var($_REQUEST, 'modal')) {
                 evt_add("reload current panel");
             }
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #9
0
 /**
  * Edit specific webpage
  *
  * @access public
  * @param void
  * @return null
  */
 function edit()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add');
     $webpage = ProjectWebpages::findById(get_id());
     if (!$webpage instanceof ProjectWebpage) {
         flash_error(lang('webpage dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$webpage->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $webpage_data = array_var($_POST, 'webpage');
     if (!is_array($webpage_data)) {
         $tag_names = $webpage->getTagNames();
         $webpage_data = array('url' => $webpage->getUrl(), 'title' => $webpage->getTitle(), 'description' => $webpage->getDescription(), 'tags' => is_array($tag_names) ? implode(', ', $tag_names) : '', 'is_private' => $webpage->isPrivate());
         // array
     }
     // if
     if (is_array(array_var($_POST, 'webpage'))) {
         //MANAGE CONCURRENCE WHILE EDITING
         $upd = array_var($_POST, 'updatedon');
         if ($upd && $webpage->getUpdatedOn()->getTimestamp() > $upd && !array_var($_POST, 'merge-changes') == 'true') {
             ajx_current('empty');
             evt_add("handle edit concurrence", array("updatedon" => $webpage->getUpdatedOn()->getTimestamp(), "genid" => array_var($_POST, 'genid')));
             return;
         }
         if (array_var($_POST, 'merge-changes') == 'true') {
             $this->setTemplate('view');
             $edited_wp = ProjectWebpages::findById($webpage->getId());
             ajx_set_no_toolbar(true);
             ajx_set_panel(lang('tab name', array('name' => $edited_wp->getTitle())));
             tpl_assign('object', $edited_wp);
             ajx_extra_data(array("title" => $edited_wp->getTitle(), 'icon' => 'ico-webpage'));
             return;
         }
         try {
             $old_is_private = $webpage->isPrivate();
             $webpage->setFromAttributes($webpage_data);
             // Options are reserved only for members of owner company
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $webpage->setIsPrivate($old_is_private);
             }
             // if
             DB::beginWork();
             $webpage->save();
             $webpage->setTagsFromCSV(array_var($webpage_data, 'tags'));
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($webpage);
             $object_controller->link_to_new_object($webpage);
             $object_controller->add_subscribers($webpage);
             $object_controller->add_custom_properties($webpage);
             ApplicationLogs::createLog($webpage, $webpage->getWorkspaces(), ApplicationLogs::ACTION_EDIT);
             $webpage->resetIsRead();
             DB::commit();
             flash_success(lang('success edit webpage', $webpage->getTitle()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
     tpl_assign('webpage', $webpage);
     tpl_assign('webpage_data', $webpage_data);
 }
コード例 #10
0
 /**
  * Add single mail
  *
  * @access public
  * @param void
  * @return null
  */
 function add_mail()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->addHelper('textile');
     $mail_accounts = MailAccounts::getMailAccountsByUser(logged_user());
     if (count($mail_accounts) < 1) {
         flash_error(lang('no mail accounts set'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_mail');
     $mail_data = array_var($_POST, 'mail');
     $sendBtnClick = array_var($mail_data, 'sendBtnClick', '') == 'true' ? true : false;
     $isDraft = array_var($mail_data, 'isDraft', '') == 'true' ? true : false;
     $isUpload = array_var($mail_data, 'isUpload', '') == 'true' ? true : false;
     $autosave = array_var($mail_data, 'autosave', '') == 'true';
     $id = array_var($mail_data, 'id');
     $mail = MailContents::findById($id);
     $isNew = false;
     if (!$mail) {
         $isNew = true;
         $mail = new MailContent();
     }
     tpl_assign('mail_to', urldecode(array_var($_GET, 'to')));
     tpl_assign('link_to_objects', array_var($_GET, 'link_to_objects'));
     $def_acc_id = $this->getDefaultAccountId();
     if ($def_acc_id > 0) {
         $def_acc = MailAccounts::getAccountById($def_acc_id);
         if ($def_acc instanceof MailAccount) {
             tpl_assign('default_account', $def_acc);
         }
     }
     tpl_assign('mail', $mail);
     tpl_assign('mail_data', $mail_data);
     tpl_assign('mail_accounts', $mail_accounts);
     Hook::fire('send_to', array_var($_GET, 'ids'), array_var($_GET, 'me'));
     // Form is submited
     if (is_array($mail_data)) {
         $account = MailAccounts::findById(array_var($mail_data, 'account_id'));
         if (!$account instanceof MailAccount) {
             flash_error(lang('mail account dnx'));
             ajx_current("empty");
             return;
         }
         $accountUser = MailAccountContacts::getByAccountAndContact($account, logged_user());
         if (!$accountUser instanceof MailAccountContact) {
             flash_error(lang('no access permissions'));
             ajx_current("empty");
             return;
         }
         if ($account->getOutgoingTrasnportType() == 'ssl' || $account->getOutgoingTrasnportType() == 'tls') {
             $available_transports = stream_get_transports();
             if (array_search($account->getOutgoingTrasnportType(), $available_transports) === FALSE) {
                 flash_error('The server does not support SSL.');
                 ajx_current("empty");
                 return;
             }
         }
         $cp_errs = $this->checkRequiredCustomPropsBeforeSave(array_var($_POST, 'object_custom_properties', array()));
         if (is_array($cp_errs) && count($cp_errs) > 0) {
             foreach ($cp_errs as $err) {
                 flash_error($err);
             }
             ajx_current("empty");
             return;
         }
         $subject = array_var($mail_data, 'subject');
         $body = array_var($mail_data, 'body');
         if (($pre_body_fname = array_var($mail_data, 'pre_body_fname')) != "") {
             $body = str_replace(lang('content too long not loaded'), '', $body, $count = 1);
             $tmp_filename = ROOT . "/tmp/{$pre_body_fname}";
             if (is_file($tmp_filename)) {
                 $body .= file_get_contents($tmp_filename);
                 if (!$isDraft) {
                     @unlink($tmp_filename);
                 }
             }
         }
         if (array_var($mail_data, 'format') == 'html') {
             $css = "font-family:sans-serif,Arial,Verdana; font-size:14px; line-height:1.6; color:#222;";
             Hook::fire('email_base_css', null, $css);
             str_replace(array("\r", "\n"), "", $css);
             $body = '<div style="' . $css . '">' . $body . '</div>';
             $body = str_replace('<blockquote>', '<blockquote style="border-left:1px solid #987ADD;padding-left:10px;">', $body);
         }
         $type = 'text/' . array_var($mail_data, 'format');
         $to = trim(array_var($mail_data, 'to'));
         if (str_ends_with($to, ",") || str_ends_with($to, ";")) {
             $to = substr($to, 0, strlen($to) - 1);
         }
         $mail_data['to'] = $to;
         $cc = trim(array_var($mail_data, 'cc'));
         if (str_ends_with($cc, ",") || str_ends_with($cc, ";")) {
             $cc = substr($cc, 0, strlen($cc) - 1);
         }
         $mail_data['cc'] = $cc;
         $bcc = trim(array_var($mail_data, 'bcc'));
         if (str_ends_with($bcc, ",") || str_ends_with($bcc, ";")) {
             $bcc = substr($bcc, 0, strlen($bcc) - 1);
         }
         $mail_data['bcc'] = $bcc;
         if (!$isDraft && trim($to . $cc . $bcc) == '') {
             flash_error(lang('recipient must be specified'));
             ajx_current("empty");
             return;
         }
         $invalid_to = MailUtilities::validate_email_addresses($to);
         if (is_array($invalid_to)) {
             flash_error(lang('error invalid recipients', lang('mail to'), implode(", ", $invalid_to)));
             ajx_current("empty");
             return;
         }
         $invalid_cc = MailUtilities::validate_email_addresses($cc);
         if (is_array($invalid_cc)) {
             flash_error(lang('error invalid recipients', lang('mail CC'), implode(", ", $invalid_cc)));
             ajx_current("empty");
             return;
         }
         $invalid_bcc = MailUtilities::validate_email_addresses($bcc);
         if (is_array($invalid_bcc)) {
             flash_error(lang('error invalid recipients', lang('mail BCC'), implode(", ", $invalid_bcc)));
             ajx_current("empty");
             return;
         }
         $last_mail_in_conversation = array_var($mail_data, 'last_mail_in_conversation');
         $conversation_id = array_var($mail_data, 'conversation_id');
         if ($last_mail_in_conversation && $conversation_id) {
             $new_mail_in_conversation = MailContents::getLastMailIdInConversation($conversation_id, true);
             if ($new_mail_in_conversation != $last_mail_in_conversation) {
                 ajx_current("empty");
                 evt_add("new email in conversation", array('id' => $new_mail_in_conversation, 'genid' => array_var($_POST, 'instanceName')));
                 return;
             }
         }
         $mail->setFromAttributes($mail_data);
         $mail->setTo($to);
         $mail->setCc($cc);
         $mail->setBcc($bcc);
         $mail->setSubject($mail_data['subject']);
         $utils = new MailUtilities();
         // attachment
         $linked_attachments = array();
         $attachments = array();
         $project_files_attachments = array();
         $objects = array_var($_POST, 'linked_objects');
         $attach_contents = array_var($_POST, 'attach_contents', array());
         $original_email = isset($mail_data['original_id']) ? MailContents::findById($mail_data['original_id']) : null;
         if (is_array($objects)) {
             $err = 0;
             $count = -1;
             foreach ($objects as $objid) {
                 $count++;
                 $split = explode(":", $objid);
                 if (count($split) == 2) {
                     $object = Objects::instance()->findObject($split[1]);
                 } else {
                     if (count($split) == 4) {
                         if ($split[0] == 'FwdMailAttach') {
                             $tmp_filename = ROOT . "/tmp/" . logged_user()->getId() . "_" . ($original_email ? $original_email->getAccountId() : $mail_data['account_id']) . "_FwdMailAttach_" . $split[3];
                             if (is_file($tmp_filename)) {
                                 $attachments[] = array("data" => file_get_contents($tmp_filename), "name" => $split[1], "type" => $split[2]);
                                 continue;
                             }
                         }
                     }
                 }
                 if (!isset($object) || !$object) {
                     flash_error(lang('file dnx'));
                     $err++;
                 } else {
                     if (isset($attach_contents[$count])) {
                         if ($split[0] == 'ProjectFiles') {
                             $file = ProjectFiles::findById($object->getId());
                             if (!$file instanceof ProjectFile) {
                                 flash_error(lang('file dnx'));
                                 $err++;
                             }
                             // if
                             //			 					if(!$file->canDownload(logged_user())) {
                             //			 						flash_error(lang('no access permissions'));
                             //			 						$err++;
                             //			 					} // if
                             $project_files_attachments[] = $file;
                             $attachments[] = array("data" => $file->getFileContent(), "name" => $file->getFilename(), "type" => $file->getTypeString());
                         } else {
                             if ($split[0] == 'MailContents') {
                                 $email = MailContents::findById($object->getId());
                                 if (!$email instanceof MailContent) {
                                     flash_error(lang('email dnx'));
                                     $err++;
                                 }
                                 // if
                                 if (!$email->canView(logged_user())) {
                                     flash_error(lang('no access permissions'));
                                     $err++;
                                 }
                                 // if
                                 $attachments[] = array("data" => $email->getContent(), "name" => $email->getSubject() . ".eml", "type" => 'message/rfc822');
                             }
                         }
                     } else {
                         $linked_attachments[] = array("data" => $object->getViewUrl(), "name" => clean($object->getObjectName()), "type" => lang($object->getObjectTypeName()), "id" => $object->getId());
                     }
                 }
             }
             if ($err > 0) {
                 flash_error(lang('some objects could not be linked', $err));
                 ajx_current('empty');
                 return;
             }
         }
         $to = preg_split('/;|,/', $to);
         $to = $utils->parse_to($to);
         if ($body == '') {
             $body .= ' ';
         }
         try {
             $linked_users = array();
             //create contacts from recipients of email
             if (user_config_option('create_contacts_from_email_recipients') || can_manage_contacts(logged_user())) {
                 foreach ($to as $to_user) {
                     $linked_user = Contacts::getByEmail($to_user[1]);
                     if (!$linked_user instanceof Contact) {
                         try {
                             DB::beginWork();
                             $linked_user = create_user_from_email($to_user[1], $to_user[0], null, false);
                             DB::commit();
                         } catch (Exception $e) {
                             Logger::log($e->getMessage());
                             DB::rollback();
                         }
                     }
                     if ($linked_user instanceof Contact) {
                         $linked_users[] = $linked_user;
                     }
                 }
             }
             if (count($linked_attachments)) {
                 $linked_atts = $type == 'text/html' ? '<div style="font-family:arial;"><br><br><br><span style="font-size:12pt;font-weight:bold;color:#777">' . lang('linked attachments') . '</span><ul>' : "\n\n\n-----------------------------------------\n" . lang('linked attachments') . "\n\n";
                 foreach ($linked_attachments as $att) {
                     $linked_atts .= $type == 'text/html' ? '<li><a href="' . $att['data'] . '">' . $att['name'] . ' (' . $att['type'] . ')</a></li>' : $att['name'] . ' (' . $att['type'] . '): ' . $att['data'] . "\n";
                     foreach ($linked_users as $linked_user) {
                         try {
                             $linked_user->giveAccessToObject(Objects::findObject($att['id']));
                         } catch (Exception $e) {
                             //Logger::log($e->getMessage());
                         }
                     }
                 }
                 $linked_atts .= $type == 'text/html' ? '</ul></div>' : '';
             } else {
                 $linked_atts = '';
             }
             $body .= $linked_atts;
             if (count($attachments) > 0) {
                 $i = 0;
                 $str = "";
                 /*	foreach ($attachments as $att) {
                 					$str .= "--000000000000000000000000000$i\n";
                 					$str .= "Name: ".$att['name'] .";\n";
                 					$str .= "Type: ".$att['type'] .";\n";
                 					//$str .= "Encoding: ".$att['type'] .";\n";
                 					$str .= base64_encode($att['data']) ."\n";
                 					$str .= "--000000000000000000000000000$i--\n";
                 					$i++;
                 				}
                 			*/
                 $str = "#att_ver 2\n";
                 foreach ($attachments as $att) {
                     $rep_id = $utils->saveContent($att['data']);
                     if (str_starts_with($att['name'], "#")) {
                         $att['name'] = str_replace_first("#", "@@sharp@@", $att['name']);
                     }
                     $str .= $att['name'] . "|" . $att['type'] . "|" . $rep_id . "\n";
                 }
                 // save attachments, when mail is sent this file is deleted and full content is saved
                 $repository_id = $utils->saveContent($str);
                 if (!$isNew) {
                     if (FileRepository::isInRepository($mail->getContentFileId())) {
                         // delete old attachments
                         $content = FileRepository::getFileContent($mail->getContentFileId());
                         if (str_starts_with($content, "#att_ver")) {
                             $lines = explode("\n", $content);
                             foreach ($lines as $line) {
                                 if (!str_starts_with($line, "#") && trim($line) !== "") {
                                     $data = explode("|", $line);
                                     if (isset($data[2]) && FileRepository::isInRepository($data[2])) {
                                         FileRepository::deleteFile($data[2]);
                                     }
                                 }
                             }
                         }
                         FileRepository::deleteFile($mail->getContentFileId());
                     }
                 }
                 $mail->setContentFileId($repository_id);
             }
             $mail->setHasAttachments(is_array($attachments) && count($attachments) > 0 ? 1 : 0);
             $mail->setAccountEmail($account->getEmailAddress());
             $mail->setSentDate(DateTimeValueLib::now());
             $mail->setReceivedDate(DateTimeValueLib::now());
             DB::beginWork();
             $msg_id = MailUtilities::generateMessageId($account->getEmailAddress());
             $conversation_id = array_var($mail_data, 'conversation_id');
             $in_reply_to_id = array_var($mail_data, 'in_reply_to_id');
             if ($conversation_id) {
                 $in_reply_to = MailContents::findById(array_var($mail_data, 'original_id'));
                 if ($in_reply_to instanceof MailContent && $in_reply_to->getSubject() && strpos(strtolower($mail->getSubject()), strtolower($in_reply_to->getSubject())) === false) {
                     $conversation_id = null;
                     $in_reply_to_id = '';
                 }
             }
             if (!$conversation_id) {
                 $conversation_id = MailContents::getNextConversationId($account->getId());
             }
             $mail->setMessageId($msg_id);
             $mail->setConversationId($conversation_id);
             $mail->setInReplyToId($in_reply_to_id);
             $mail->setUid(gen_id());
             $mail->setState($isDraft && !$sendBtnClick ? 2 : 200);
             set_user_config_option('last_mail_format', array_var($mail_data, 'format', 'plain'), logged_user()->getId());
             $body = utf8_safe($body);
             if (array_var($mail_data, 'format') == 'html') {
                 $body = preg_replace("/<body*[^>]*>/i", '<body>', $body);
                 // commented because sometimes brokes the html and leaves the body in blank
                 //$body = convert_to_links(preg_replace("/<body*[^>]*>/i",'<body>', $body));
                 $mail->setBodyHtml($body);
                 $mail->setBodyPlain(utf8_safe(html_to_text($body)));
             } else {
                 $mail->setBodyPlain($body);
                 $mail->setBodyHtml('');
             }
             $mail->setFrom($account->getEmailAddress());
             if ($accountUser->getIsDefault() && $accountUser->getSenderName() == "") {
                 $mail->setFromName(logged_user()->getObjectName());
             } else {
                 $mail->setFromName($accountUser->getSenderName());
             }
             $mail->save();
             //$mail->setIsRead(logged_user()->getId(), true);
             if (Plugins::instance()->isActivePlugin('mail_rules')) {
                 if (array_var($mail_data, 'format') == 'html') {
                     $img = MailTracks::get_track_mark_img($mail->getId());
                     $body = $body . $img;
                     $mail->setBodyHtml($body);
                     $mail->setBodyPlain(utf8_safe(html_to_text($body)));
                     $mail->save();
                 }
             }
             foreach ($project_files_attachments as $pfatt) {
                 if ($pfatt instanceof ProjectFile) {
                     $pfatt->setMailId($mail->getId());
                     $pfatt->save();
                     $pfatt->addToSharingTable();
                 }
             }
             $member_ids = active_context_members(false);
             // if replying a classified email classify on same workspace
             $classified_with_conversation = false;
             if (array_var($mail_data, 'original_id')) {
                 $in_reply_to = MailContents::findById(array_var($mail_data, 'original_id'));
                 if ($in_reply_to instanceof MailContent) {
                     $member_ids = array_merge($member_ids, $in_reply_to->getMemberIds());
                     $classified_with_conversation = true;
                 }
             }
             // autoclassify sent email if not classified
             if (!$classified_with_conversation) {
                 $acc_mem_ids = explode(',', $account->getMemberId());
                 foreach ($acc_mem_ids as $acc_mem_id) {
                     $member_ids[] = $acc_mem_id;
                 }
             }
             $object_controller = new ObjectController();
             foreach ($member_ids as $k => &$mem_id) {
                 if ($mem_id == "") {
                     unset($member_ids[$k]);
                 }
             }
             if (count($member_ids) > 0) {
                 //$object_controller->add_to_members($mail, $member_ids);
                 $members = Members::instance()->findAll(array('conditions' => 'id IN (' . implode(',', $member_ids) . ')'));
                 $mail->addToMembers($members, true);
                 $mail->addToSharingTable();
             }
             $object_controller->link_to_new_object($mail);
             $object_controller->add_subscribers($mail);
             /*
             				if (array_var($mail_data, 'link_to_objects') != ''){
             					$lto = explode('|', array_var($mail_data, 'link_to_objects'));
             					foreach ($lto as $object_string){
             						$split_object = explode('-', $object_string);
             						$object = Objects::findObject($split_object[1]);
             						if ($object instanceof ContentDataObject){
             							$mail->linkObject($object);
             						}
             					}
             				}*/
             //subscribe user
             $user = Contacts::findById($account->getContactId());
             if ($user instanceof Contact) {
                 $mail->subscribeUser($user);
             }
             /*if (user_config_option('create_contacts_from_email_recipients') && can_manage_contacts(logged_user())) {
             			// automatically create contacts
             			foreach ($to as $recipient) {
             				$recipient_name = trim($recipient[0]);
             				$recipient_address = trim($recipient[1]);
             				if (!$recipient_address) continue;
             				$contact = Contacts::getByEmail($recipient_address);
             				if (!$contact instanceof Contact) {
             					try {
             						$contact = new Contact();
             						$contact->addEmail($recipient_address, 'personal');
             						if ($recipient_name && $recipient_name != $recipient_address) {
             							$contact->setFirstName($recipient_name);
             						} else {
             							$index = strpos($recipient_address, "@");
             							$recipient_name = substr($recipient_address, 0, $index);
             							$contact->setFirstName($recipient_name);
             						}
             						$contact->save();
             					} catch (Exception $e) {
             						Logger::log($e->getMessage());
             					}
             				}
             			}
             		}*/
             $mail->addToSharingTable();
             $mail->orderConversation();
             DB::commit();
             ApplicationLogs::createLog($mail, ApplicationLogs::ACTION_ADD, false, true);
             $mail->setIsRead(logged_user()->getId(), true);
             if (!$autosave) {
                 if ($isDraft && !$sendBtnClick) {
                     flash_success(lang('success save mail'));
                     ajx_current("empty");
                 } else {
                     evt_add("must send mails", array("account" => $mail->getAccountId()));
                     //flash_success(lang('mail is being sent'));
                     ajx_current("back");
                 }
                 evt_add("email saved", array("id" => $mail->getId(), "instance" => array_var($_POST, 'instanceName')));
             } else {
                 evt_add("draft mail autosaved", array("id" => $mail->getId(), "hf_id" => $mail_data['hf_id']));
                 flash_success(lang('success autosave draft'));
                 ajx_current("empty");
             }
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #11
0
 /**
  * Show and process edit milestone form
  *
  * @access public
  * @param void
  * @return null
  */
 function edit()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_milestone');
     if (array_var($_REQUEST, "template_milestone")) {
         $milestone = TemplateMilestones::findById(get_id());
         $this->setTemplate(get_template_path('add_template_milestone', 'template_milestone'));
         if (!$milestone instanceof TemplateMilestone) {
             flash_error(lang('milestone dnx'));
             ajx_current("empty");
             return;
         }
         // if
     } else {
         $milestone = ProjectMilestones::findById(get_id());
         if (!$milestone instanceof ProjectMilestone) {
             flash_error(lang('milestone dnx'));
             ajx_current("empty");
             return;
         }
         // if
     }
     if (!$milestone->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $milestone_data = array_var($_POST, 'milestone');
     if (!is_array($milestone_data)) {
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
         $milestone_data = array('name' => $milestone->getObjectName(), 'due_date' => $milestone->getDueDate(), 'description' => $milestone->getDescription(), 'is_urgent' => $milestone->getIsUrgent());
         // array
     }
     // if
     tpl_assign('milestone_data', $milestone_data);
     tpl_assign('milestone', $milestone);
     if (is_array(array_var($_POST, 'milestone'))) {
         if (array_var($milestone_data, 'due_date_value') != '') {
             $milestone_data['due_date'] = getDateValue(array_var($milestone_data, 'due_date_value'));
         } else {
             $now = DateTimeValueLib::now();
             $milestone_data['due_date'] = DateTimeValueLib::make(0, 0, 0, $now->getMonth(), $now->getDay(), $now->getYear());
         }
         $milestone->setFromAttributes($milestone_data);
         $urgent = array_var($milestone_data, 'is_urgent');
         $milestone->setIsUrgent($urgent);
         try {
             $member_ids = json_decode(array_var($_POST, 'members'));
             DB::beginWork();
             $milestone->save();
             $object_controller = new ObjectController();
             $object_controller->add_to_members($milestone, $member_ids);
             $object_controller->add_subscribers($milestone);
             $object_controller->link_to_new_object($milestone);
             $object_controller->add_custom_properties($milestone);
             $object_controller->add_reminders($milestone);
             DB::commit();
             ApplicationLogs::createLog($milestone, ApplicationLogs::ACTION_EDIT);
             //Send Template milestone to view
             if ($milestone instanceof TemplateMilestone) {
                 $object = array("action" => "edit", "object_id" => $milestone->getObjectId(), "type" => $milestone->getObjectTypeName(), "id" => $milestone->getId(), "name" => $milestone->getObjectName(), "ico" => "ico-milestone", "manager" => get_class($milestone->manager()));
                 evt_add("template object added", array('object' => $object));
             }
             $is_template = $milestone instanceof TemplateMilestone;
             if (array_var($_REQUEST, 'modal')) {
                 ajx_current("empty");
                 $this->setLayout("json");
                 $this->setTemplate(get_template_path("empty"));
                 // reload milestone info because plugins may have updated some task info (for example: name prefix)
                 if ($is_template) {
                     $milestone = TemplateMilestones::findById($milestone->getId());
                     $params = array('msg' => lang('success edit milestone', $milestone->getObjectName()), 'milestone' => $milestone->getArrayInfo(), 'reload' => array_var($_REQUEST, 'reload'));
                     if ($milestone instanceof TemplateMilestone) {
                         $params = $object;
                     }
                     print_modal_json_response($params, true, array_var($_REQUEST, 'use_ajx'));
                 } else {
                     $milestone = ProjectMilestones::findById($milestone->getId());
                     flash_success(lang('success edit milestone', $milestone->getObjectName()));
                     evt_add("reload current panel");
                 }
             } else {
                 if ($milestone instanceof TemplateMilestone) {
                     flash_success(lang('success edit template', $milestone->getObjectName()));
                 } else {
                     flash_success(lang('success edit milestone', $milestone->getObjectName()));
                 }
                 if (array_var($task_data, 'inputtype') != 'taskview') {
                     ajx_current("back");
                 } else {
                     ajx_current("reload");
                 }
             }
             /*
             				flash_success(lang('success edit milestone', $milestone->getObjectName()));
             				if (array_var($_REQUEST, 'modal')) {
             					evt_add("reload current panel");
             				}
             				ajx_current("back");*/
         } catch (Exception $e) {
             DB::rollback();
             if (array_var($_REQUEST, 'modal')) {
                 $this->setLayout("json");
                 $this->setTemplate(get_template_path("empty"));
                 print_modal_json_response(array('errorCode' => 1, 'errorMessage' => $e->getMessage()));
             } else {
                 flash_error($e->getMessage());
             }
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #12
0
 /**
  * Edit client
  *
  * @param void
  * @return null
  */
 function edit_client()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_company');
     $company = Companies::findById(get_id());
     if (!$company->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$company instanceof Company) {
         flash_error(lang('client dnx'));
         ajx_current("empty");
         return;
     }
     // if
     $company_data = array_var($_POST, 'company');
     if (!is_array($company_data)) {
         $tag_names = $company->getTagNames();
         $company_data = array('name' => $company->getName(), 'tags' => is_array($tag_names) ? implode(', ', $tag_names) : '', 'timezone' => $company->getTimezone(), 'email' => $company->getEmail(), 'homepage' => $company->getHomepage(), 'address' => $company->getAddress(), 'address2' => $company->getAddress2(), 'city' => $company->getCity(), 'state' => $company->getState(), 'zipcode' => $company->getZipcode(), 'country' => $company->getCountry(), 'phone_number' => $company->getPhoneNumber(), 'fax_number' => $company->getFaxNumber(), 'notes' => $company->getNotes());
         // array
     }
     // if
     tpl_assign('company', $company);
     tpl_assign('company_data', $company_data);
     if (is_array(array_var($_POST, 'company'))) {
         $company->setFromAttributes($company_data);
         $is_owner_company = false;
         if (owner_company()->getId() == $company->getId()) {
             $company->setClientOfId(0);
             $is_owner_company = true;
         } else {
             $company->setClientOfId(owner_company()->getId());
         }
         $company->setHomepage(array_var($company_data, 'homepage'));
         try {
             DB::beginWork();
             $company->save();
             $company->setTagsFromCSV(array_var($company_data, 'tags'));
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($company, !can_manage_contacts(logged_user()));
             $object_controller->link_to_new_object($company);
             $object_controller->add_subscribers($company);
             $object_controller->add_custom_properties($company);
             ApplicationLogs::createLog($company, $company->getWorkspaces(), ApplicationLogs::ACTION_EDIT);
             DB::commit();
             // Update global cache
             if ($is_owner_company && GlobalCache::isAvailable()) {
                 GlobalCache::update('owner_company', $company);
             }
             flash_success(lang('success edit client', $company->getName()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
     // if
 }
コード例 #13
0
ファイル: functions.php プロジェクト: abhinay100/feng_app
/**
 * Copies related data from an object to another (members, linked_objects, custom_properties, subscribers, reminders and comments)
 * @param $object: Original object to copy data
 * @param $copy: Object to be modified with the data of the $orignal object
 * @param $options: set which type of data will not be copied
 */
function copy_additional_object_data($object, &$copy, $options = array())
{
    if (!$object instanceof ContentDataObject || !$copy instanceof ContentDataObject) {
        // if not valid objects return
        return;
    }
    $copy_members = !array_var($options, 'dont_copy_members');
    $copy_linked_objects = !array_var($options, 'dont_copy_linked_objects');
    $copy_custom_properties = !array_var($options, 'dont_copy_custom_properties');
    $copy_subscribers = !array_var($options, 'dont_copy_subscribers');
    $copy_reminders = !array_var($options, 'dont_copy_reminders');
    $copy_comments = !array_var($options, 'dont_copy_comments');
    $controller = new ObjectController();
    // copy members
    if ($copy_members) {
        $object_members = $object->getMembers();
        $copy->addToMembers($object_members);
        Hook::fire('after_add_to_members', $copy, $object_members);
        $copy->addToSharingTable();
    }
    // copy linked objects
    if ($copy_linked_objects) {
        $copy->copyLinkedObjectsFrom($object);
    }
    // copy custom properties
    if ($copy_custom_properties) {
        // custom properties defined in "settings"
        $cp_object_type_id = $object->getObjectTypeId();
        if ($object instanceof TemplateTask || $object instanceof TemplateMilestone) {
            $cp_object_type_id = $copy->getObjectTypeId();
        }
        $custom_props = CustomProperties::getAllCustomPropertiesByObjectType($cp_object_type_id);
        foreach ($custom_props as $c_prop) {
            $values = CustomPropertyValues::getCustomPropertyValues($object->getId(), $c_prop->getId());
            if (is_array($values)) {
                foreach ($values as $val) {
                    $cp = new CustomPropertyValue();
                    $cp->setObjectId($copy->getId());
                    $cp->setCustomPropertyId($val->getCustomPropertyId());
                    $cp->setValue($val->getValue());
                    $cp->save();
                }
            }
        }
        // object properties (key-value)
        $copy->copyCustomPropertiesFrom($object);
    }
    // copy subscribers
    if ($copy_subscribers) {
        $subscribers_array = array();
        foreach ($object->getSubscriberIds() as $user_id) {
            $subscribers_array["user_" . $user_id] = "1";
        }
        $controller->add_subscribers($copy, $subscribers_array);
    }
    // copy reminders
    if ($copy_reminders) {
        $reminders = ObjectReminders::getByObject($object);
        foreach ($reminders as $reminder) {
            $copy_reminder = new ObjectReminder();
            $copy_reminder->setContext($reminder->getContext());
            $reminder_date = $copy->getColumnValue($reminder->getContext());
            if ($reminder_date instanceof DateTimeValue) {
                $reminder_date = new DateTimeValue($reminder_date->getTimestamp());
                $reminder_date->add('m', -$reminder->getMinutesBefore());
            }
            $copy_reminder->setDate($reminder_date);
            $copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
            $copy_reminder->setObject($copy);
            $copy_reminder->setType($reminder->getType());
            $copy_reminder->setUserId($reminder->getUserId());
            $copy_reminder->save();
        }
    }
    // copy comments
    if ($copy_comments) {
        foreach ($object->getAllComments() as $com) {
            $new_com = new Comment();
            $new_com->setAuthorEmail($com->getAuthorEmail());
            $new_com->setAuthorName($com->getAuthorName());
            $new_com->setAuthorHomepage($com->getAuthorHomepage());
            $new_com->setCreatedById($com->getCreatedById());
            $new_com->setCreatedOn($com->getCreatedOn());
            $new_com->setUpdatedById($com->getUpdatedById());
            $new_com->setUpdatedOn($com->getUpdatedOn());
            $new_com->setText($com->getText());
            $new_com->setRelObjectId($copy->getId());
            $new_com->save();
        }
    }
}
コード例 #14
0
 function checkin_file()
 {
     $this->setTemplate('add_file');
     $file = ProjectFiles::findById(get_id());
     if (!$file instanceof ProjectFile) {
         flash_error(lang('file dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$file->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $file_data = array_var($_POST, 'file');
     if (!is_array($file_data)) {
         $tag_names = $file->getTagNames();
         $file_data = array('description' => $file->getDescription(), 'is_private' => $file->getIsPrivate(), 'is_important' => $file->getIsImportant(), 'comments_enabled' => $file->getCommentsEnabled(), 'anonymous_comments_enabled' => $file->getAnonymousCommentsEnabled(), 'tags' => is_array($tag_names) && count($tag_names) ? implode(', ', $tag_names) : '', 'workspaces' => $file->getWorkspacesNamesCSV(logged_user()->getWorkspacesQuery()));
         // array
     }
     // if
     tpl_assign('file', $file);
     tpl_assign('file_data', $file_data);
     tpl_assign('checkin', true);
     if (is_array(array_var($_POST, 'file'))) {
         try {
             $old_is_private = $file->isPrivate();
             $old_is_important = $file->getIsImportant();
             $old_comments_enabled = $file->getCommentsEnabled();
             $old_anonymous_comments_enabled = $file->getAnonymousCommentsEnabled();
             DB::beginWork();
             $handle_file = true;
             // change file?
             $post_revision = $handle_file && array_var($file_data, 'version_file_change') == 'checked';
             // post revision?
             $revision_comment = $post_revision ? trim(array_var($file_data, 'revision_comment')) : '';
             // user comment?
             $file->setFromAttributes($file_data);
             $file->setFilename(array_var($file_data, 'name'));
             $file->checkIn();
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $file->setIsPrivate($old_is_private);
                 $file->setIsImportant($old_is_important);
                 $file->setCommentsEnabled($old_comments_enabled);
                 $file->setAnonymousCommentsEnabled($old_anonymous_comments_enabled);
             }
             // if
             $file->save();
             $file->setTagsFromCSV(array_var($file_data, 'tags'));
             if ($handle_file) {
                 // handle uploaded file
                 $upload_id = array_var($file_data, 'upload_id');
                 $uploaded_file = array_var($_SESSION, $upload_id, array());
                 $file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment);
                 // handle uploaded file
                 @unlink($uploaded_file['tmp_name']);
             }
             // if
             $ws = $file->getWorkspaces();
             $object_controller = new ObjectController();
             $object_controller->link_to_new_object($file);
             $object_controller->add_subscribers($file);
             $object_controller->add_custom_properties($file);
             ApplicationLogs::createLog($file, $ws, ApplicationLogs::ACTION_EDIT);
             ApplicationLogs::createLog($file, $file->getWorkspaces(), ApplicationLogs::ACTION_CHECKIN);
             DB::commit();
             flash_success(lang('success add file', $file->getFilename()));
             ajx_current("back");
         } catch (Exception $e) {
             //@unlink($file->getFilePath());
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #15
0
 /**
  * Add company
  *
  * @param void
  * @return null
  */
 function add_company()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $notAllowedMember = '';
     if (!Contact::canAdd(logged_user(), active_context(), $notAllowedMember)) {
         if (str_starts_with($notAllowedMember, '-- req dim --')) {
             flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
         } else {
             trim($notAllowedMember) == "" ? flash_error(lang('you must select where to keep', lang('the contact'))) : flash_error(lang('no context permissions to add', lang("contacts"), $notAllowedMember));
         }
         ajx_current("empty");
         return;
     }
     // if
     $company = new Contact();
     $company->setIsCompany(1);
     $company_data = array_var($_POST, 'company');
     if (!is_array($company_data)) {
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
         $company_data = array('timezone' => logged_user()->getTimezone());
         // array
     }
     // if
     tpl_assign('company', $company);
     tpl_assign('company_data', $company_data);
     // telephone types
     $all_telephone_types = TelephoneTypes::getAllTelephoneTypesInfo();
     tpl_assign('all_telephone_types', $all_telephone_types);
     // address types
     $all_address_types = AddressTypes::getAllAddressTypesInfo();
     tpl_assign('all_address_types', $all_address_types);
     // webpage types
     $all_webpage_types = WebpageTypes::getAllWebpageTypesInfo();
     tpl_assign('all_webpage_types', $all_webpage_types);
     // email types
     $all_email_types = EmailTypes::getAllEmailTypesInfo();
     tpl_assign('all_email_types', $all_email_types);
     $company_data['all_phones'] = array();
     $company_data['all_addresses'] = array();
     $company_data['all_webpages'] = array();
     if (is_array(array_var($_POST, 'company'))) {
         foreach ($company_data as $k => &$v) {
             $v = remove_scripts($v);
         }
         $company->setFromAttributes($company_data);
         $company->setObjectName();
         try {
             $company_data['contact_type'] = 'company';
             Contacts::validate($company_data);
             DB::beginWork();
             if (isset($_SESSION['new_contact_picture']) && $_SESSION['new_contact_picture']) {
                 $company->setPictureFile($_SESSION['new_contact_picture']);
                 $_SESSION['new_contact_picture'] = null;
             }
             $company->save();
             // save phones, addresses and webpages
             $this->save_phones_addresses_webpages($company_data, $company);
             if ($company_data['email'] != "") {
                 $company->addEmail($company_data['email'], 'work', true);
             }
             // save additional emails
             $this->save_non_main_emails($company_data, $company);
             $object_controller = new ObjectController();
             $object_controller->add_subscribers($company);
             $member_ids = json_decode(array_var($_POST, 'members'));
             if (!is_null($member_ids)) {
                 $object_controller->add_to_members($company, $member_ids);
             }
             $object_controller->link_to_new_object($company);
             $object_controller->add_custom_properties($company);
             DB::commit();
             ApplicationLogs::createLog($company, ApplicationLogs::ACTION_ADD);
             flash_success(lang('success add client', $company->getObjectName()));
             evt_add("company added", array("id" => $company->getObjectId(), "name" => $company->getObjectName()));
             ajx_current("back");
             if (array_var($_REQUEST, 'modal')) {
                 evt_add("reload current panel");
             }
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             if (array_var($_REQUEST, 'modal')) {
                 ajx_extra_data(array('error' => $e->getMessage()));
             } else {
                 flash_error($e->getMessage());
             }
         }
         // try
     }
     // if
 }
コード例 #16
0
	function checkin_file() {
		$this->setTemplate('add_file');

		$file = ProjectFiles::findById(get_id());
		if(!($file instanceof ProjectFile)) {
			flash_error(lang('file dnx'));
			ajx_current("empty");
			return;
		} // if
			
		if(!$file->canEdit(logged_user())) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		} // if
			
		$file_data = array_var($_POST, 'file');
		if(!is_array($file_data)) {
			$file_data = array(
				'description' => $file->getDescription(),
			); // array
		} // if
		tpl_assign('file', $file);
		tpl_assign('file_data', $file_data);
		tpl_assign('checkin', true);
			
		if(is_array(array_var($_POST, 'file'))) {
			try {
				DB::beginWork();
				$handle_file      = true; // change file?
				$post_revision    = $handle_file && array_var($file_data, 'version_file_change') == 'checked'; // post revision?
				$revision_comment = $post_revision ? trim(array_var($file_data, 'revision_comment')) : ''; // user comment?

				$file->setFromAttributes($file_data);
				$file->setFilename(array_var($file_data, 'name'));
				$file->checkIn();

				$file->save();
				
				if ($handle_file) {
					// handle uploaded file
					$upload_id = array_var($file_data, 'upload_id');
					$uploaded_file = array_var($_SESSION, $upload_id, array());
					$file->handleUploadedFile($uploaded_file, $post_revision, $revision_comment); // handle uploaded file
					@unlink($uploaded_file['tmp_name']);
				} // if

				$object_controller = new ObjectController();
				$object_controller->link_to_new_object($file);
				$object_controller->add_subscribers($file);
				$object_controller->add_custom_properties($file);

				//subscribe user if not subscribed
				if(!$file->isSubscriber(logged_user())) {				
					$file->subscribeUser(logged_user());
				} // if
				
				ApplicationLogs::createLog($file, ApplicationLogs::ACTION_EDIT);
				ApplicationLogs::createLog($file, ApplicationLogs::ACTION_CHECKIN);
				DB::commit();

				flash_success(lang('success add file', $file->getFilename()));
				ajx_current("back");
			} catch(Exception $e) {
				
				DB::rollback();
				flash_error($e->getMessage());
				ajx_current("empty");
			} // try
		} // if
	} // checkin_file
コード例 #17
0
 function cloneTask($new_st_date = '', $new_due_date = '', $copy_status = false, $copy_repeat_options = true, $parent_subtask = 0)
 {
     $new_task = new TemplateTask();
     if ($parent_subtask != 0) {
         $new_task->setParentId($parent_subtask);
     } else {
         $new_task->setParentId($this->getParentId());
     }
     $new_task->setObjectName($this->getObjectName());
     $new_task->setText($this->getText());
     $new_task->setAssignedToContactId($this->getAssignedToContactId());
     $new_task->setAssignedOn($this->getAssignedOn());
     $new_task->setAssignedById($this->getAssignedById());
     $new_task->setTimeEstimate($this->getTimeEstimate());
     $new_task->setStartedOn($this->getStartedOn());
     $new_task->setStartedById($this->getStartedById());
     $new_task->setPriority($this->getPriority());
     $new_task->setState($this->getState());
     $new_task->setOrder($this->getOrder());
     $new_task->setMilestoneId($this->getMilestoneId());
     $new_task->setFromTemplateId($this->getFromTemplateId());
     $new_task->setUseStartTime($this->getUseStartTime());
     $new_task->setUseDueTime($this->getUseDueTime());
     $new_task->setTypeContent($this->getTypeContent());
     if ($this->getParentId() == 0) {
         //if not subtask
         if ($this->getOriginalTaskId() == 0) {
             $new_task->setOriginalTaskId($this->getObjectId());
         } else {
             $new_task->setOriginalTaskId($this->getOriginalTaskId());
         }
     }
     if ($this->getDueDate() instanceof DateTimeValue) {
         $new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
     }
     if ($this->getStartDate() instanceof DateTimeValue) {
         $new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
     }
     if ($copy_status) {
         $new_task->setCompletedById($this->getCompletedById());
         $new_task->setCompletedOn($this->getCompletedOn());
     }
     if ($copy_repeat_options) {
         $new_task->setRepeatEnd($this->getRepeatEnd());
         $new_task->setRepeatForever($this->getRepeatForever());
         $new_task->setRepeatNum($this->getRepeatNum());
         $new_task->setRepeatBy($this->getRepeatBy());
         $new_task->setRepeatD($this->getRepeatD());
         $new_task->setRepeatM($this->getRepeatM());
         $new_task->setRepeatY($this->getRepeatY());
     }
     if ($new_st_date != "") {
         if ($new_task->getStartDate() instanceof DateTimeValue) {
             $new_task->setStartDate($new_st_date);
         }
     }
     if ($new_due_date != "") {
         if ($new_task->getDueDate() instanceof DateTimeValue) {
             $new_task->setDueDate($new_due_date);
         }
     }
     $new_task->save();
     if (is_array($this->getAllLinkedObjects())) {
         foreach ($this->getAllLinkedObjects() as $lo) {
             $new_task->linkObject($lo);
         }
     }
     $sub_tasks = $this->getAllSubTasks();
     foreach ($sub_tasks as $st) {
         $new_dates = $this->getNextRepetitionDatesSubtask($st, $new_task, $new_st_date, $new_due_date);
         if ($st->getParentId() == $this->getId()) {
             $new_st = $st->cloneTask(array_var($new_dates, 'st'), array_var($new_dates, 'due'), $copy_status, $copy_repeat_options, $new_task->getId());
             if ($copy_status) {
                 $new_st->setCompletedById($st->getCompletedById());
                 $new_st->setCompletedOn($st->getCompletedOn());
                 $new_st->save();
             }
             $new_task->attachTask($new_st);
         }
     }
     foreach ($this->getAllComments() as $com) {
         $new_com = new Comment();
         $new_com->setAuthorEmail($com->getAuthorEmail());
         $new_com->setAuthorName($com->getAuthorName());
         $new_com->setAuthorHomepage($com->getAuthorHomepage());
         $new_com->setCreatedById($com->getCreatedById());
         $new_com->setCreatedOn($com->getCreatedOn());
         $new_com->setUpdatedById($com->getUpdatedById());
         $new_com->setUpdatedOn($com->getUpdatedOn());
         $new_com->setText($com->getText());
         $new_com->setRelObjectId($new_task->getId());
         $new_com->save();
     }
     $_POST['subscribers'] = array();
     foreach ($this->getSubscribers() as $sub) {
         $_POST['subscribers']["user_" . $sub->getId()] = "checked";
     }
     $obj_controller = new ObjectController();
     $obj_controller->add_to_members($new_task, $this->getMemberIds());
     $obj_controller->add_subscribers($new_task);
     foreach ($this->getCustomProperties() as $prop) {
         $new_prop = new ObjectProperty();
         $new_prop->setRelObjectId($new_task->getId());
         $new_prop->setPropertyName($prop->getPropertyName());
         $new_prop->setPropertyValue($prop->getPropertyValue());
         $new_prop->save();
     }
     $custom_props = CustomProperties::getAllCustomPropertiesByObjectType("TemplateTasks");
     foreach ($custom_props as $c_prop) {
         $values = CustomPropertyValues::getCustomPropertyValues($this->getId(), $c_prop->getId());
         if (is_array($values)) {
             foreach ($values as $val) {
                 $cp = new CustomPropertyValue();
                 $cp->setObjectId($new_task->getId());
                 $cp->setCustomPropertyId($val->getCustomPropertyId());
                 $cp->setValue($val->getValue());
                 $cp->save();
             }
         }
     }
     $reminders = ObjectReminders::getByObject($this);
     foreach ($reminders as $reminder) {
         $copy_reminder = new ObjectReminder();
         $copy_reminder->setContext($reminder->getContext());
         $reminder_date = $new_task->getColumnValue($reminder->getContext());
         if ($reminder_date instanceof DateTimeValue) {
             $reminder_date = new DateTimeValue($reminder_date->getTimestamp());
             $reminder_date->add('m', -$reminder->getMinutesBefore());
         }
         $copy_reminder->setDate($reminder_date);
         $copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
         $copy_reminder->setObject($new_task);
         $copy_reminder->setType($reminder->getType());
         $copy_reminder->setUserId($reminder->getUserId());
         $copy_reminder->save();
     }
     return $new_task;
 }
コード例 #18
0
 /**
  * Edit specific webpage
  *
  * @access public
  * @param void
  * @return null
  */
 function edit()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add');
     $webpage = ProjectWebpages::findById(get_id());
     if (!$webpage instanceof ProjectWebpage) {
         flash_error(lang('webpage dnx'));
         ajx_current("empty");
         return;
     }
     if (!$webpage->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $webpage_data = array_var($_POST, 'webpage');
     if (!is_array($webpage_data)) {
         $webpage_data = array('url' => $webpage->getUrl(), 'name' => $webpage->getObjectName(), 'description' => $webpage->getDescription());
     }
     if (is_array(array_var($_POST, 'webpage'))) {
         try {
             $webpage->setFromAttributes($webpage_data);
             DB::beginWork();
             $webpage->save();
             $member_ids = json_decode(array_var($_POST, 'members'));
             $object_controller = new ObjectController();
             $object_controller->add_to_members($webpage, $member_ids);
             $object_controller->link_to_new_object($webpage);
             $object_controller->add_subscribers($webpage);
             $object_controller->add_custom_properties($webpage);
             ApplicationLogs::createLog($webpage, ApplicationLogs::ACTION_EDIT);
             $webpage->resetIsRead();
             DB::commit();
             flash_success(lang('success edit webpage', $webpage->getObjectName()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
     }
     tpl_assign('webpage', $webpage);
     tpl_assign('webpage_data', $webpage_data);
 }
コード例 #19
0
 /**
  * Edit specific message
  *
  * @access public
  * @param void
  * @return null
  */
 function edit()
 {
     $this->setTemplate('add_message');
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current('empty');
         return;
     }
     $message = ProjectMessages::findById(get_id());
     if (!$message instanceof ProjectMessage) {
         flash_error(lang('message dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$message->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $message_data = array_var($_POST, 'message');
     if (!is_array($message_data)) {
         $tag_names = $message->getTagNames();
         $message_data = array('milestone_id' => $message->getMilestoneId(), 'title' => $message->getTitle(), 'text' => $message->getText(), 'additional_text' => $message->getAdditionalText(), 'tags' => is_array($tag_names) ? implode(', ', $tag_names) : '', 'is_private' => $message->isPrivate(), 'is_important' => $message->getIsImportant(), 'comments_enabled' => $message->getCommentsEnabled(), 'anonymous_comments_enabled' => $message->getAnonymousCommentsEnabled());
         // array
     }
     // if
     tpl_assign('message', $message);
     tpl_assign('message_data', $message_data);
     if (is_array(array_var($_POST, 'message'))) {
         try {
             //MANAGE CONCURRENCE WHILE EDITING
             $upd = array_var($_POST, 'updatedon');
             if ($upd && $message->getUpdatedOn()->getTimestamp() > $upd && !array_var($_POST, 'merge-changes') == 'true') {
                 ajx_current('empty');
                 evt_add("handle edit concurrence", array("updatedon" => $message->getUpdatedOn()->getTimestamp(), "genid" => array_var($_POST, 'genid')));
                 return;
             }
             if (array_var($_POST, 'merge-changes') == 'true') {
                 $this->setTemplate('view');
                 $edited_note = ProjectMessages::findById($message->getId());
                 tpl_assign('message', $edited_note);
                 tpl_assign('subscribers', $edited_note->getSubscribers());
                 ajx_extra_data(array("title" => $edited_note->getTitle(), 'icon' => 'ico-message'));
                 ajx_set_no_toolbar(true);
                 ajx_set_panel(lang('tab name', array('name' => $edited_note->getTitle())));
                 return;
             }
             $old_is_private = $message->isPrivate();
             $old_is_important = $message->getIsImportant();
             $old_comments_enabled = $message->getCommentsEnabled();
             $old_anonymous_comments_enabled = $message->getAnonymousCommentsEnabled();
             $message->setFromAttributes($message_data);
             // Options are reserved only for members of owner company
             if (!logged_user()->isMemberOfOwnerCompany()) {
                 $message->setIsPrivate($old_is_private);
                 $message->setIsImportant($old_is_important);
                 $message->setCommentsEnabled($old_comments_enabled);
                 $message->setAnonymousCommentsEnabled($old_anonymous_comments_enabled);
             }
             // if
             DB::beginWork();
             $message->save();
             $message->setTagsFromCSV(array_var($message_data, 'tags'));
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($message);
             $object_controller->link_to_new_object($message);
             $object_controller->add_subscribers($message);
             $object_controller->add_custom_properties($message);
             $message->resetIsRead();
             ApplicationLogs::createLog($message, $message->getWorkspaces(), ApplicationLogs::ACTION_EDIT);
             DB::commit();
             flash_success(lang('success edit message', $message->getTitle()));
             if (array_var($_POST, 'popup', false)) {
                 ajx_current("reload");
             } else {
                 ajx_current("back");
             }
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }
コード例 #20
0
	/**
	 * Add company
	 *
	 * @param void
	 * @return null
	 */
	function add_company() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		$notAllowedMember = '';				
		if(!Contact::canAdd(logged_user(),active_context(),$notAllowedMember)) {
			if (str_starts_with($notAllowedMember, '-- req dim --')) flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in)));
			else flash_error(lang('no context permissions to add',lang("contacts"), $notAllowedMember));
			ajx_current("empty");
			return;
		} // if
		
		$company = new Contact();
		$company->setIsCompany(1);
		$company_data = array_var($_POST, 'company');

		if(!is_array($company_data)) {
			$company_data = array(
				'timezone' => logged_user()->getTimezone(),
			); // array
		} // if
		tpl_assign('company', $company);
		tpl_assign('company_data', $company_data);
	
		if (is_array(array_var($_POST, 'company'))) {
                    
			$company->setFromAttributes($company_data);
			$company->setObjectName();

	

			try {
				Contacts::validate($company_data); 
				DB::beginWork();
				$company->save();
				if($company_data['address'] != "")
				$company->addAddress($company_data['address'], $company_data['city'], $company_data['state'], $company_data['country'], $company_data['zipcode'], 'work', true);
				if($company_data['phone_number'] != "") $company->addPhone($company_data['phone_number'], 'work', true);
				if($company_data['fax_number'] != "") $company->addPhone($company_data['fax_number'], 'fax', true);
				if($company_data['homepage'] != "") $company->addWebpage($company_data['homepage'], 'work');
				if($company_data['email'] != "") $company->addEmail($company_data['email'], 'work' , true);
				
				$object_controller = new ObjectController();
				$object_controller->add_subscribers($company);

				$member_ids = json_decode(array_var($_POST, 'members'));
				if (!is_null($member_ids)) {
					$object_controller->add_to_members($company, $member_ids);
				}
				$object_controller->link_to_new_object($company);
				$object_controller->add_custom_properties($company);
				
				ApplicationLogs::createLog($company, ApplicationLogs::ACTION_ADD);

				DB::commit();

				flash_success(lang('success add client', $company->getObjectName()));
				evt_add("company added", array("id" => $company->getObjectId(), "name" => $company->getObjectName()));
				ajx_current("back");
			} catch(Exception $e) {
				DB::rollback();
				ajx_current("empty");
				flash_error($e->getMessage());
			} // try
		} // if
	} // add_company
コード例 #21
0
 /**
  * Edit specific contact
  *
  * @access public
  * @param void
  * @return null
  */
 function edit()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('edit_contact');
     if (active_project() instanceof Project) {
         tpl_assign('isAddProject', true);
     }
     $contact = Contacts::findById(get_id());
     if (!$contact instanceof Contact) {
         flash_error(lang('contact dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$contact->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $im_types = ImTypes::findAll(array('order' => '`id`'));
     $active_project = active_project();
     $role = "";
     if ($active_project) {
         $pc = $contact->getRole(active_project());
         if ($pc instanceof ProjectContact) {
             $role = $pc->getRole();
         }
     }
     $contact_data = array_var($_POST, 'contact');
     if (!is_array($contact_data)) {
         $tag_names = $contact->getTagNames();
         $contact_data = array('firstname' => $contact->getFirstName(), 'lastname' => $contact->getLastName(), 'middlename' => $contact->getMiddleName(), 'department' => $contact->getDepartment(), 'job_title' => $contact->getJobTitle(), 'email' => $contact->getEmail(), 'email2' => $contact->getEmail2(), 'email3' => $contact->getEmail3(), 'w_web_page' => $contact->getWWebPage(), 'w_address' => $contact->getWAddress(), 'w_city' => $contact->getWCity(), 'w_state' => $contact->getWState(), 'w_zipcode' => $contact->getWZipcode(), 'w_country' => $contact->getWCountry(), 'w_phone_number' => $contact->getWPhoneNumber(), 'w_phone_number2' => $contact->getWPhoneNumber2(), 'w_fax_number' => $contact->getWFaxNumber(), 'w_assistant_number' => $contact->getWAssistantNumber(), 'w_callback_number' => $contact->getWCallbackNumber(), 'h_web_page' => $contact->getHWebPage(), 'h_address' => $contact->getHAddress(), 'h_city' => $contact->getHCity(), 'h_state' => $contact->getHState(), 'h_zipcode' => $contact->getHZipcode(), 'h_country' => $contact->getHCountry(), 'h_phone_number' => $contact->getHPhoneNumber(), 'h_phone_number2' => $contact->getHPhoneNumber2(), 'h_fax_number' => $contact->getHFaxNumber(), 'h_mobile_number' => $contact->getHMobileNumber(), 'h_pager_number' => $contact->getHPagerNumber(), 'o_web_page' => $contact->getOWebPage(), 'o_address' => $contact->getOAddress(), 'o_city' => $contact->getOCity(), 'o_state' => $contact->getOState(), 'o_zipcode' => $contact->getOZipcode(), 'o_country' => $contact->getOCountry(), 'o_phone_number' => $contact->getOPhoneNumber(), 'o_phone_number2' => $contact->getOPhoneNumber2(), 'o_fax_number' => $contact->getOFaxNumber(), 'o_birthday' => $contact->getOBirthday(), 'picture_file' => $contact->getPictureFile(), 'timezone' => $contact->getTimezone(), 'notes' => $contact->getNotes(), 'is_private' => $contact->getIsPrivate(), 'company_id' => $contact->getCompanyId(), 'role' => $role, 'tags' => is_array($tag_names) ? implode(', ', $tag_names) : '');
         // array
         if (is_array($im_types)) {
             foreach ($im_types as $im_type) {
                 $contact_data['im_' . $im_type->getId()] = $contact->getImValue($im_type);
             }
             // forech
         }
         // if
         $default_im = $contact->getDefaultImType();
         $contact_data['default_im'] = $default_im instanceof ImType ? $default_im->getId() : '';
     }
     // if
     tpl_assign('contact', $contact);
     tpl_assign('contact_data', $contact_data);
     tpl_assign('im_types', $im_types);
     if (is_array(array_var($_POST, 'contact'))) {
         //	MANAGE CONCURRENCE WHILE EDITING
         $upd = array_var($_POST, 'updatedon');
         if ($upd && $contact->getUpdatedOn()->getTimestamp() > $upd && !array_var($_POST, 'merge-changes') == 'true') {
             ajx_current('empty');
             evt_add("handle edit concurrence", array("updatedon" => $contact->getUpdatedOn()->getTimestamp(), "genid" => array_var($_POST, 'genid')));
             return;
         }
         if (array_var($_POST, 'merge-changes') == 'true') {
             $this->setTemplate('card');
             $new_contact = Contacts::findById($contact->getId());
             ajx_set_panel(lang('tab name', array('name' => $new_contact->getDisplayName())));
             ajx_extra_data(array("title" => $new_contact->getDisplayName(), 'icon' => 'ico-contact'));
             ajx_set_no_toolbar(true);
             //ajx_set_panel(lang ('tab name',array('name'=>$new_contact->getDisplayName())));
             return;
         }
         try {
             DB::beginWork();
             $newCompany = false;
             if (array_var($contact_data, 'isNewCompany') == 'true' && is_array(array_var($_POST, 'company'))) {
                 $company_data = array_var($_POST, 'company');
                 $company = new Company();
                 $company->setFromAttributes($company_data);
                 $company->setClientOfId(1);
                 $company->save();
                 ApplicationLogs::createLog($company, null, ApplicationLogs::ACTION_ADD);
                 $newCompany = true;
                 if (active_project() instanceof Project && $company->canAdd(logged_user(), active_project())) {
                     $company->addToWorkspace(active_project());
                 } else {
                     $company->addToWorkspace(logged_user()->getPersonalProject());
                 }
             }
             $contact_data['o_birthday'] = getDateValue(array_var($contact_data, "o_birthday_value", ''));
             $contact->setFromAttributes($contact_data);
             /*if (!is_null($contact->getOBirthday()) && $contact_data["o_birthday_year"] == 0){
             			$contact->setOBirthday(null);
             		} else if ($contact_data["o_birthday_year"] != 0) {
             			$bday = new DateTimeValue(0);
             			$bday->setYear($contact_data["o_birthday_year"]);
             			$bday->setMonth($contact_data["o_birthday_month"]);
             			$bday->setDay($contact_data["o_birthday_day"]);
             			$contact->setOBirthday($bday);
             		}*/
             if ($newCompany) {
                 $contact->setCompanyId($company->getId());
             }
             $contact->save();
             $contact->setTagsFromCSV(array_var($contact_data, 'tags'));
             $contact->clearImValues();
             foreach ($im_types as $im_type) {
                 $value = trim(array_var($contact_data, 'im_' . $im_type->getId()));
                 if ($value != '') {
                     $contact_im_value = new ContactImValue();
                     $contact_im_value->setContactId($contact->getId());
                     $contact_im_value->setImTypeId($im_type->getId());
                     $contact_im_value->setValue($value);
                     $contact_im_value->setIsDefault(array_var($contact_data, 'default_im') == $im_type->getId());
                     $contact_im_value->save();
                 }
                 // if
             }
             // foreach
             $object_controller = new ObjectController();
             $object_controller->add_to_workspaces($contact, !can_manage_contacts(logged_user()));
             $object_controller->link_to_new_object($contact);
             $object_controller->add_subscribers($contact);
             $object_controller->add_custom_properties($contact);
             ApplicationLogs::createLog($contact, null, ApplicationLogs::ACTION_EDIT);
             DB::commit();
             if (trim(array_var($contact_data, 'role', '')) != '' && active_project() instanceof Project) {
                 if (!ProjectContact::canAdd(logged_user(), active_project())) {
                     flash_error(lang('error contact added but not assigned', $contact->getDisplayName(), active_project()->getName()));
                     ajx_current("back");
                     return;
                 }
                 // if
                 $pc = $contact->getRole(active_project());
                 if (!$pc instanceof ProjectContact) {
                     $pc = new ProjectContact();
                     $pc->setContactId($contact->getId());
                     $pc->setProjectId(active_project()->getId());
                 }
                 $pc->setRole(array_var($contact_data, 'role'));
                 $pc->save();
                 //ApplicationLogs::createLog($contact, $contact->getWorkspaces(), ApplicationLogs::ACTION_ADD);
             }
             flash_success(lang('success edit contact', $contact->getDisplayName()));
             ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     }
     // if
 }