/**
  * 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
 }
Exemplo n.º 2
0
/**
 * @deprecated Use HTMLPurifier
 */
function remove_scripts($html)
{
    if (is_array($html)) {
        foreach ($html as $k => &$v) {
            $v = remove_scripts($v);
        }
        return $html;
    }
    return preg_replace('/<script[^>]*>.*(<\\/script[^>]*>|$)/i', '', $html);
}
Exemplo n.º 3
0
 /**
  * Edit file properties
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_file()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $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)) {
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
         $file_data = array('description' => $file->getDescription(), 'attach_to_notification' => $file->getAttachToNotification(), 'default_subject' => $file->getDefaultSubject(), 'file_id' => get_id());
         // array
     }
     // if
     tpl_assign('file', $file);
     tpl_assign('file_data', $file_data);
     if (is_array(array_var($_POST, 'file'))) {
         foreach ($file_data as $k => &$v) {
             $v = remove_scripts($v);
         }
         try {
             DB::beginWork();
             $handle_file = array_var($file_data, 'update_file');
             // change file?
             $post_revision = $handle_file && array_var($file_data, 'version_file_change');
             // post revision?
             $revision_comment = trim(array_var($file_data, 'revision_comment'));
             // user comment?
             $file->setFromAttributes($file_data);
             $file->setAttachToNotification(array_var($file_data, 'attach_to_notification'));
             if (array_var($file_data, 'default_subject_sel') == 'subject') {
                 $file->setDefaultSubject(array_var($file_data, 'default_subject_text'));
             } else {
                 $file->setDefaultSubject('');
             }
             $fname = array_var($file_data, 'name');
             $ext = trim(array_var($file_data, 'extension'));
             if ($ext != '') {
                 $fname .= "." . $ext;
             }
             $file->setFilename($fname);
             if ($file->getType() == ProjectFiles::TYPE_WEBLINK) {
                 $url = array_var($file_data, 'url', '');
                 if ($url && strpos($url, ':') === false) {
                     $url = $this->protocol . $url;
                 }
                 $file->setUrl($url);
                 $revision = $file->getLastRevision();
                 /* @var $revision ProjectFileRevision */
                 if (!$revision instanceof ProjectFileRevision || $post_revision) {
                     $revision = new ProjectFileRevision();
                     $revision->setFileId($file->getId());
                     $revision->setRevisionNumber($file->getNextRevisionNumber());
                     $revision->setFileTypeId(FileTypes::getByExtension('webfile')->getId());
                     $revision->setRepositoryId('webfile');
                     $revision->setComment($revision_comment);
                 }
                 $revision->setTypeString($file->getUrl());
                 $revision->save();
             }
             $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
             $member_ids = json_decode(array_var($_POST, 'members'));
             $object_controller = new ObjectController();
             $object_controller->add_to_members($file, $member_ids);
             $object_controller->link_to_new_object($file);
             $object_controller->add_subscribers($file);
             $object_controller->add_custom_properties($file);
             $file->resetIsRead();
             DB::commit();
             set_user_config_option('notify_myself_too', array_var($file_data, 'notify_myself_too'));
             if (array_var($file_data, 'notify_myself_too')) {
                 logged_user()->notify_myself = true;
             }
             ApplicationLogs::createLog($file, ApplicationLogs::ACTION_EDIT);
             if (array_var($file_data, 'notify_myself_too')) {
                 logged_user()->notify_myself = false;
             }
             flash_success(lang('success edit file', $file->getFilename()));
             ajx_current("back");
             if (array_var($_REQUEST, 'modal')) {
                 evt_add("reload current panel");
             }
         } 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(), 'showMessage' => 1), true, true);
             } else {
                 flash_error($e->getMessage());
             }
             ajx_current("empty");
         }
         // try
     }
     // if
 }
Exemplo n.º 4
0
 /**
  * Set value of 'text' field
  *
  * @access public
  * @param string $value
  * @return boolean
  */
 function setText($value)
 {
     $value = remove_scripts($value);
     return $this->setColumnValue('text', $value);
 }
 /**
  * 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
 }
Exemplo n.º 6
0
 /**
  * Edit task
  *
  * @access public
  * @param void
  * @return null
  */
 function edit_task()
 {
     $isTemplateTask = false;
     if (array_var($_REQUEST, 'template_task') == true) {
         $isTemplateTask = true;
     }
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_task');
     if (array_var($_REQUEST, "template_task")) {
         $task = TemplateTasks::findById(array_var($_REQUEST, "template_task_id", get_id()));
         $this->setTemplate(get_template_path('add_template_task', 'template_task'));
         if (array_var($_REQUEST, 'template_id')) {
             $template_id = array_var($_REQUEST, 'template_id');
         } else {
             $template_id = $task->getTemplateId();
         }
         tpl_assign('additional_tt_params', array_var($_REQUEST, 'additional_tt_params'));
         tpl_assign('template_id', $template_id);
         if (!$task instanceof TemplateTask) {
             flash_error(lang('task list dnx'));
             ajx_current("empty");
             return;
         }
         // if
     } else {
         $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
     }
     if (array_var($_GET, 'replace')) {
         ajx_replace(true);
     }
     $task_data = array_var($_POST, 'task');
     $time_estimate = array_var($_POST, 'hours', 0) * 60 + array_var($_POST, 'minutes', 0);
     if ($time_estimate > 0) {
         $estimatedTime = $time_estimate;
     } else {
         $estimatedTime = $task->getTimeEstimate();
     }
     if (!is_array($task_data)) {
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
         $this->getRepeatOptions($task, $occ, $rsel1, $rsel2, $rsel3, $rnum, $rend, $rjump);
         $dd = $task->getDueDate() instanceof DateTimeValue ? $task->getDueDate() : null;
         if ($dd instanceof DateTimeValue && $task->getUseDueTime()) {
             $dd->advance(logged_user()->getTimezone() * 3600);
         }
         $sd = $task->getStartDate() instanceof DateTimeValue ? $task->getStartDate() : null;
         if ($sd instanceof DateTimeValue && $task->getUseStartTime()) {
             $sd->advance(logged_user()->getTimezone() * 3600);
         }
         $post_dd = null;
         if (array_var($_POST, 'task_due_date')) {
             $post_dd = getDateValue(array_var($_POST, 'task_due_date'));
             if ($post_dd instanceof DateTimeValue) {
                 $duetime = getTimeValue(array_var($_POST, 'task_due_time'));
                 if (is_array($duetime)) {
                     $post_dd->setHour(array_var($duetime, 'hours'));
                     $post_dd->setMinute(array_var($duetime, 'mins'));
                     $post_dd->advance(logged_user()->getTimezone() * 3600);
                 }
             }
         }
         $post_st = null;
         if (array_var($_POST, 'task_start_date')) {
             $post_st = getDateValue(array_var($_POST, 'task_start_date'));
             if ($post_st instanceof DateTimeValue) {
                 $starttime = getTimeValue(array_var($_POST, 'task_start_time'));
                 if (is_array($starttime)) {
                     $post_st->setHour(array_var($starttime, 'hours'));
                     $post_st->setMinute(array_var($starttime, 'mins'));
                     $post_st->advance(logged_user()->getTimezone() * 3600);
                 }
             }
         }
         if (config_option("wysiwyg_tasks")) {
             $text_post = preg_replace("/[\n|\r|\n\r]/", '', array_var($_POST, 'text', $task->getText()));
         } else {
             $text_post = array_var($_POST, 'text', $task->getText());
         }
         $task_data = array('name' => array_var($_POST, 'name', $task->getObjectName()), 'text' => $text_post, 'milestone_id' => array_var($_POST, 'milestone_id', $task->getMilestoneId()), 'due_date' => getDateValue($post_dd, $dd), 'start_date' => getDateValue($post_st, $sd), 'parent_id' => $task->getParentId(), 'assigned_to_contact_id' => array_var($_POST, 'assigned_to_contact_id', $task->getAssignedToContactId()), 'selected_members_ids' => json_decode(array_var($_POST, 'members', null)), 'priority' => array_var($_POST, 'priority', $task->getPriority()), 'time_estimate' => $estimatedTime, 'percent_completed' => $task->getPercentCompleted(), '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')), 'type_content' => $task->getTypeContent(), 'multi_assignment' => $task->getColumnValue('multi_assignment', 0), 'send_notification_subscribers' => user_config_option("can notify subscribers"));
         // array
         //control dates of parent and subtasks
         $task_data['type_control'] = "";
         $parent_data = $task->getParent();
         if ($parent_data) {
             $task_data['type_control'] = "child";
             $task_data['control_title'] = $parent_data->getObjectName();
             $task_data['control_due_date'] = $parent_data->getDueDate() instanceof DateTimeValue ? $parent_data->getDueDate()->getTimestamp() + logged_user()->getTimezone() * 3600 : null;
             $task_data['control_start_date'] = $parent_data->getStartDate() instanceof DateTimeValue ? $parent_data->getStartDate()->getTimestamp() + logged_user()->getTimezone() * 3600 : null;
         }
         $subtask_data = $task->getAllSubTasks();
         if ($subtask_data) {
             $task_data['type_control'] = "father";
             $task_data['control_title'] = $task->getObjectName();
             $task_data['control_due_date'] = getDateValue($post_dd, $dd) instanceof DateTimeValue ? getDateValue($post_dd, $dd)->getTimestamp() : null;
             $task_data['control_start_date'] = getDateValue($post_st, $sd) instanceof DateTimeValue ? getDateValue($post_st, $sd)->getTimestamp() : null;
         }
     }
     // if
     //I find all those related to the task to find out if the original
     $task_related = ProjectTasks::findByRelated($task->getObjectId());
     if (!$task_related) {
         //is not the original as the original look plus other related
         if ($task->getOriginalTaskId() != "0") {
             $task_related = ProjectTasks::findByTaskAndRelated($task->getObjectId(), $task->getOriginalTaskId());
         }
     }
     if ($task_related) {
         $pending_id = 0;
         foreach ($task_related as $t_rel) {
             if ($task->getStartDate() <= $t_rel->getStartDate() && $task->getDueDate() <= $t_rel->getDueDate() && !$t_rel->isCompleted()) {
                 $pending_id = $t_rel->getId();
                 break;
             }
         }
         tpl_assign('pending_task_id', $pending_id);
         tpl_assign('task_related', true);
     } else {
         tpl_assign('pending_task_id', 0);
         tpl_assign('task_related', false);
     }
     tpl_assign('task', $task);
     tpl_assign('task_data', $task_data);
     if (is_array(array_var($_POST, 'task'))) {
         foreach ($task_data as $k => &$v) {
             $v = remove_scripts($v);
         }
         $send_edit = false;
         if ($task->getAssignedToContactId() == array_var($task_data, 'assigned_to_contact_id')) {
             $send_edit = true;
         }
         $old_owner = $task->getAssignedTo();
         if (array_var($task_data, 'parent_id') == $task->getId()) {
             flash_error(lang("task own parent error"));
             ajx_current("empty");
             return;
         }
         try {
             try {
                 $task_data['due_date'] = getDateValue(array_var($_POST, 'task_due_date'));
                 $task_data['start_date'] = getDateValue(array_var($_POST, 'task_start_date'));
             } catch (Exception $e) {
                 throw new Exception(lang('date format error', date_format_tip(user_config_option('date_format'))));
             }
             if ($task_data['due_date'] instanceof DateTimeValue) {
                 $duetime = getTimeValue(array_var($_POST, 'task_due_time'));
                 if (is_array($duetime)) {
                     $task_data['due_date']->setHour(array_var($duetime, 'hours'));
                     $task_data['due_date']->setMinute(array_var($duetime, 'mins'));
                     $task_data['due_date']->advance(logged_user()->getTimezone() * -3600);
                 }
                 $task_data['use_due_time'] = is_array($duetime);
             }
             if ($task_data['start_date'] instanceof DateTimeValue) {
                 $starttime = getTimeValue(array_var($_POST, 'task_start_time'));
                 if (is_array($starttime)) {
                     $task_data['start_date']->setHour(array_var($starttime, 'hours'));
                     $task_data['start_date']->setMinute(array_var($starttime, 'mins'));
                     $task_data['start_date']->advance(logged_user()->getTimezone() * -3600);
                 }
                 $task_data['use_start_time'] = is_array($starttime);
             }
             //control date subtask whit parent
             if (array_var($_POST, 'control_dates') == "child") {
                 $parent = $task->getParent();
                 if ($parent->getStartDate() instanceof DateTimeValue && $task_data['start_date'] instanceof DateTimeValue) {
                     if ($task_data['start_date']->getTimestamp() < $parent->getStartDate()->getTimestamp()) {
                         $parent->setStartDate($task_data['start_date']);
                         $parent->setUseStartTime($task_data['use_start_time']);
                     }
                 } else {
                     $parent->setStartDate($task_data['start_date']);
                     $parent->setUseStartTime(array_var($task_data, 'use_start_time', 0));
                 }
                 if ($parent->getDueDate() instanceof DateTimeValue && $task_data['due_date'] instanceof DateTimeValue) {
                     if ($task_data['due_date']->getTimestamp() > $parent->getDueDate()->getTimestamp()) {
                         $parent->setDueDate($task_data['due_date']);
                         $parent->setUseDueTime($task_data['use_due_time']);
                     }
                 } else {
                     $parent->setDueDate($task_data['due_date']);
                     $parent->setUseDueTime(array_var($task_data, 'use_due_time', 0));
                 }
                 // calculate and set estimated time
                 $totalMinutes = array_var($task_data, 'time_estimate_hours') * 60 + array_var($task_data, 'time_estimate_minutes');
                 $parent->setTimeEstimate($totalMinutes);
                 $parent->save();
             }
             $err_msg = $this->setRepeatOptions($task_data);
             if ($err_msg) {
                 throw new Exception($err_msg);
             }
             if (!isset($task_data['parent_id'])) {
                 $task_data['parent_id'] = 0;
             }
             $member_ids = json_decode(array_var($_POST, 'members'));
             // keep old dates to check for subtasks
             $old_start_date = $task->getStartDate();
             $old_due_date = $task->getDueDate();
             if (config_option("wysiwyg_tasks")) {
                 $task_data['type_content'] = "html";
                 $task_data['text'] = str_replace(array("\r", "\n", "\r\n"), array('', '', ''), array_var($task_data, 'text'));
             } else {
                 $task_data['type_content'] = "text";
             }
             $task->setFromAttributes($task_data);
             $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;
             }
             if (isset($task_data['percent_completed']) && $task_data['percent_completed'] >= 0 && $task_data['percent_completed'] <= 100) {
                 $task->setPercentCompleted($task_data['percent_completed']);
             }
             DB::beginWork();
             $task->save();
             if (!isset($task_data['percent_completed'])) {
                 $task->calculatePercentComplete();
             }
             // 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()] = '1';
             }
             $object_controller = new ObjectController();
             if ($isTemplateTask) {
                 $object_controller->add_to_members($task, $member_ids, null, false);
             } else {
                 $object_controller->add_to_members($task, $member_ids);
             }
             $is_template = $task instanceof TemplateTask;
             $object_controller->add_subscribers($task, null, !$is_template);
             $object_controller->link_to_new_object($task);
             $object_controller->add_custom_properties($task);
             if (!$task->isCompleted()) {
                 //to make sure the task it is not completed yet, and that it has subscribed people
                 $old_reminders = ObjectReminders::getByObject($task);
                 $object_controller->add_reminders($task);
                 //adding the new reminders, if any
                 $object_controller->update_reminders($task, $old_reminders);
                 //updating the old ones
                 if (logged_user() instanceof Contact && (!is_array($old_reminders) || count($old_reminders) == 0) && (user_config_option("add_task_autoreminder") && logged_user()->getId() != $task->getAssignedToContactId() || user_config_option("add_self_task_autoreminder") && logged_user()->getId() == $task->getAssignedToContactId())) {
                     //if there is no asignee, but it still has subscribers
                     $reminder = new ObjectReminder();
                     $def = explode(",", user_config_option("reminders_tasks"));
                     $minutes = $def[2] * $def[1];
                     $reminder->setMinutesBefore($minutes);
                     $reminder->setType($def[0]);
                     $reminder->setContext("due_date");
                     $reminder->setObject($task);
                     $reminder->setUserId(0);
                     $date = $task->getDueDate();
                     if ($date instanceof DateTimeValue) {
                         $rdate = new DateTimeValue($date->getTimestamp() - $minutes * 60);
                         $reminder->setDate($rdate);
                     }
                     $reminder->save();
                 }
             }
             if (!is_array($member_ids) || count($member_ids) == 0) {
                 $member_ids = array(0);
             }
             $members = Members::findAll(array('conditions' => "id IN (" . implode(',', $member_ids) . ")"));
             $task->apply_members_to_subtasks($members, true);
             // apply values to subtasks
             $assigned_to = $task->getAssignedToContactId();
             $subtasks = $task->getAllSubTasks();
             $milestone_id = $task->getMilestoneId();
             $apply_ms = array_var($task_data, 'apply_milestone_subtasks');
             $apply_at = array_var($task_data, 'apply_assignee_subtasks', '');
             foreach ($subtasks as $sub) {
                 $modified = false;
                 //if ($apply_at || !($sub->getAssignedToContactId() > 0)) {
                 if ($apply_at) {
                     $sub->setAssignedToContactId($assigned_to);
                     $modified = true;
                 }
                 if ($apply_ms) {
                     $sub->setMilestoneId($milestone_id);
                     $modified = true;
                 }
                 if ($modified) {
                     $sub->save();
                 }
                 //control date parent whit subtask
                 if ($_POST['control_dates'] == "father") {
                     if ($sub->getStartDate() instanceof DateTimeValue) {
                         if ($task->getStartDate() instanceof DateTimeValue) {
                             if ($task->getStartDate()->getTimestamp() > $sub->getStartDate()->getTimestamp()) {
                                 $sub->setStartDate($task->getStartDate());
                             }
                         }
                     } else {
                         if ($task->getStartDate() instanceof DateTimeValue) {
                             $sub->setStartDate($task->getStartDate());
                         }
                     }
                     $sub->setUseStartTime($task->getUseStartTime());
                     if ($sub->getDueDate() instanceof DateTimeValue) {
                         if ($task->getDueDate() instanceof DateTimeValue) {
                             if ($task->getDueDate()->getTimestamp() < $sub->getDueDate()->getTimestamp()) {
                                 $sub->setDueDate($task->getDueDate());
                             }
                         }
                     } else {
                         if ($task->getDueDate() instanceof DateTimeValue) {
                             $sub->setDueDate($task->getDueDate());
                         }
                     }
                     $sub->setUseDueTime($task->getUseDueTime());
                     $sub->save();
                 }
             }
             $task->resetIsRead();
             $log_info = '';
             if ($send_edit == true) {
                 $log_info = $task->getAssignedToContactId();
             } else {
                 if ($send_edit == false) {
                     $task->setAssignedBy(logged_user());
                     $task->save();
                 }
             }
             if (config_option('repeating_task') == 1) {
                 $opt_rep_day['saturday'] = false;
                 $opt_rep_day['sunday'] = false;
                 if (array_var($task_data, 'repeat_saturdays', false)) {
                     $opt_rep_day['saturday'] = true;
                 }
                 if (array_var($task_data, 'repeat_sundays', false)) {
                     $opt_rep_day['sunday'] = true;
                 }
                 $this->repetitive_task($task, $opt_rep_day);
             }
             if (isset($_POST['type_related'])) {
                 if ($_POST['type_related'] == "all" || $_POST['type_related'] == "news") {
                     $task_data['members'] = json_decode(array_var($_POST, 'members'));
                     unset($task_data['due_date']);
                     unset($task_data['use_due_time']);
                     unset($task_data['start_date']);
                     unset($task_data['use_start_time']);
                     $this->repetitive_tasks_related($task, "edit", $_POST['type_related'], $task_data);
                 }
             }
             if (config_option('multi_assignment') && Plugins::instance()->isActivePlugin('crpm')) {
                 if (array_var($task_data, 'multi_assignment_aplly_change') == 'subtask') {
                     $null = null;
                     Hook::fire('edit_subtasks', $task, $null);
                 }
             }
             //for calculate member status we save de task again after the object have the members
             $task->save();
             // save subtasks added in 'subtasks' tab
             $sub_tasks_to_log = $this->saveSubtasks($task, array_var($task_data, 'subtasks'), $member_ids);
             DB::commit();
             foreach ($sub_tasks_to_log['add'] as $st_to_log) {
                 ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_ADD);
             }
             foreach ($sub_tasks_to_log['edit'] as $st_to_log) {
                 ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_EDIT);
             }
             foreach ($sub_tasks_to_log['trash'] as $st_to_log) {
                 ApplicationLogs::createLog($st_to_log, ApplicationLogs::ACTION_TRASH);
             }
             //Send Template task to view
             if ($task instanceof TemplateTask) {
                 $objectId = $task->getObjectId();
                 $id = $task->getId();
                 $objectTypeName = $task->getObjectTypeName();
                 $objectName = $task->getObjectName();
                 $manager = get_class($task->manager());
                 $milestoneId = $task instanceof TemplateTask ? $task->getMilestoneId() : '0';
                 $subTasks = $task->getSubTasks();
                 $parentId = $task->getParentId();
                 $ico = "ico-task";
                 $action = "edit";
                 $object = TemplateController::prepareObject($objectId, $id, $objectName, $objectTypeName, $manager, $action, $milestoneId, $subTasks, $parentId, $ico);
                 $template_task_data = array('object' => $object);
                 if (array_var($_REQUEST, 'additional_tt_params')) {
                     $additional_tt_params = json_decode(str_replace("'", '"', array_var($_REQUEST, 'additional_tt_params')), true);
                     foreach ($additional_tt_params as $k => $v) {
                         $template_task_data[$k] = $v;
                     }
                 }
                 if (!array_var($_REQUEST, 'modal')) {
                     evt_add("template object added", $template_task_data);
                 }
             }
             try {
                 // notify asignee
                 if (array_var($task_data, 'send_notification') && $task->getAssignedToContactId() != $task->getAssignedById()) {
                     $new_owner = $task->getAssignedTo();
                     if ($new_owner instanceof Contact) {
                         Notifier::taskAssigned($task);
                     }
                     // if
                 }
                 // if
                 if (array_var($task_data, 'send_notification')) {
                     foreach ($sub_tasks_to_log['assigned'] as $st_to_log) {
                         Notifier::taskAssigned($st_to_log);
                     }
                 }
             } catch (Exception $e) {
             }
             // try
             //notify subscribers
             $isSilent = true;
             if (array_var($task_data, 'send_notification_subscribers')) {
                 $isSilent = false;
             }
             ApplicationLogs::createLog($task, ApplicationLogs::ACTION_EDIT, false, false, true, $log_info);
             //flash_success(lang('success edit task list', $task->getObjectName()));
             if (array_var($_REQUEST, 'modal')) {
                 if (array_var($_REQUEST, 'reload')) {
                     evt_add("reload current panel");
                 } else {
                     ajx_current("empty");
                     $this->setLayout("json");
                     $this->setTemplate(get_template_path("empty"));
                     // reload task info because plugins may have updated some task info (for example: name prefix)
                     if ($is_template) {
                         $task = TemplateTasks::findById($task->getId());
                     } else {
                         $task = ProjectTasks::findById($task->getId());
                     }
                     $params = array('msg' => lang('success edit task list', $task->getObjectName()), 'task' => $task->getArrayInfo(), 'reload' => array_var($_REQUEST, 'reload'));
                     if ($task instanceof TemplateTask) {
                         //$params['msg'] = lang('success edit template', $task->getObjectName());
                         $params['object'] = $template_task_data['object'];
                     }
                     //print_modal_json_response($params, true, array_var($_REQUEST, 'use_ajx'));
                     ajx_extra_data($params);
                 }
             } else {
                 ajx_current("back");
             }
             // if has subtasks and dates were changed, ask the user if the subtasks dates should also be changed
             if ($task instanceof ProjectTask && $task->countOpenSubTasks() > 0) {
                 // check if there was any due date changes
                 $dd_advance_info = null;
                 if ($task->getDueDate() instanceof DateTimeValue && $old_due_date instanceof DateTimeValue && $old_due_date->getTimestamp() != $task->getDueDate()->getTimestamp()) {
                     $dd_to_advance_ts = $task->getDueDate()->getTimestamp() - $old_due_date->getTimestamp();
                     if ($dd_to_advance_ts != 0) {
                         $dd_advance_info = get_time_info($dd_to_advance_ts);
                     }
                 }
                 // check if there was any start date changes
                 $sd_advance_info = null;
                 if ($task->getStartDate() instanceof DateTimeValue && $old_start_date instanceof DateTimeValue && $old_start_date->getTimestamp() != $task->getStartDate()->getTimestamp()) {
                     $sd_to_advance_ts = $task->getStartDate()->getTimestamp() - $old_start_date->getTimestamp();
                     if ($sd_to_advance_ts != 0) {
                         $sd_advance_info = get_time_info($sd_to_advance_ts);
                     }
                 }
                 if ($dd_advance_info != null || $sd_advance_info != null) {
                     evt_add('ask to change subtasks dates', array('dd_diff' => $dd_advance_info, 'sd_diff' => $sd_advance_info, 'task_id' => $task->getId()));
                 }
             }
         } 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(), 'showMessage' => 1), true, array_var($_REQUEST, 'use_ajx'));
             } else {
                 flash_error($e->getMessage());
             }
             ajx_current("empty");
         }
         // try
     }
     // if
 }
Exemplo n.º 7
0
        ?>
"></span>
			    		<script>
							var crumbHtml = <?php 
        echo $crumbJs;
        ?>
;
							$("#object_crumb_<?php 
        echo $object->getId();
        ?>
").html(crumbHtml);
						</script>
						<?php 
        if ($object instanceof ProjectTask) {
            $text = strlen_utf($object->getText()) > 100 ? substr_utf(html_to_text($object->getText()), 0, 100) . "..." : strip_tags($object->getText());
            $text = remove_scripts($text);
            if (strlen_utf($text) > 0) {
                ?>
&nbsp;-&nbsp;<span class="desc nobr"><?php 
                echo $text;
                ?>
</span>
							<?php 
            }
            ?>
						<?php 
        }
        ?>
					</div>
				</td>
				
 /**
  * Adds the custom properties of an object into the database.
  * 
  * @param $object
  * @return unknown_type
  */
 function add_custom_properties($object)
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $obj_custom_properties = array_var($_POST, 'object_custom_properties');
     if (is_array($obj_custom_properties)) {
         foreach ($obj_custom_properties as $id => &$val) {
             $val = remove_scripts($val);
         }
     }
     $date_format = user_config_option('date_format');
     $date_format_tip = date_format_tip($date_format);
     $required_custom_props = array();
     $object_type_id = $object instanceof TemplateTask ? ProjectTasks::instance()->getObjectTypeId() : $object->getObjectTypeId();
     $customProps = CustomProperties::getAllCustomPropertiesByObjectType($object_type_id);
     //Sets all boolean custom properties to 0. If any boolean properties are returned, they are subsequently set to 1.
     foreach ($customProps as $cp) {
         if ($cp->getType() == 'boolean') {
             $custom_property_value = CustomPropertyValues::getCustomPropertyValue($object->getId(), $cp->getId());
             if (!$custom_property_value instanceof CustomPropertyValue) {
                 $custom_property_value = new CustomPropertyValue();
             }
             $custom_property_value->setObjectId($object->getId());
             $custom_property_value->setCustomPropertyId($cp->getId());
             $custom_property_value->setValue(0);
             $custom_property_value->save();
         }
         if ($cp->getIsRequired()) {
             $required_custom_props[] = $cp;
         }
     }
     foreach ($required_custom_props as $req_cp) {
         if (!isset($obj_custom_properties[$req_cp->getId()])) {
             throw new Exception(lang('custom property value required', $req_cp->getName()));
         }
     }
     if (is_array($obj_custom_properties)) {
         // check required custom properties
         foreach ($obj_custom_properties as $id => $value) {
             //Get the custom property
             $custom_property = null;
             foreach ($customProps as $cp) {
                 if ($cp->getId() == $id) {
                     $custom_property = $cp;
                     break;
                 }
             }
             if ($custom_property instanceof CustomProperty) {
                 // save dates in standard format "Y-m-d H:i:s", because the column type is string
                 if ($custom_property->getType() == 'date') {
                     if (is_array($value)) {
                         $newValues = array();
                         foreach ($value as $val) {
                             if (trim($val) != '' && trim($val) != $date_format_tip) {
                                 $dtv = DateTimeValueLib::dateFromFormatAndString($date_format, $val);
                                 $newValues[] = $dtv->format("Y-m-d H:i:s");
                             }
                         }
                         $value = $newValues;
                     } else {
                         if (trim($value) != '' && trim($val) != $date_format_tip) {
                             $dtv = DateTimeValueLib::dateFromFormatAndString($date_format, $value);
                             $value = $dtv->format("Y-m-d H:i:s");
                         } else {
                             $value = '';
                         }
                     }
                 }
                 foreach (array_var($_REQUEST, 'remove_custom_properties', array()) as $cpropid => $remove) {
                     if ($remove) {
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $cpropid);
                     }
                 }
                 Hook::fire('before_save_custom_property_value', array('custom_prop' => $custom_property), $value);
                 if (is_array($value)) {
                     if ($custom_property->getType() == 'address') {
                         if ($custom_property->getIsRequired()) {
                             if (array_var($value, 'street') == '' && array_var($value, 'city') == '' && array_var($value, 'state') == '' && array_var($value, 'country') == '' && array_var($value, 'zip_code') == '') {
                                 throw new Exception(lang('custom property value required', $custom_property->getName()));
                             }
                             $errors = array(lang('error form validation'));
                             Env::useHelper('form');
                             $ok = checkAddressInputMandatoryFields($value, $custom_property->getName(), $errors);
                             if (!$ok) {
                                 throw new Exception(implode("\n - ", $errors));
                             }
                         }
                         // Address custom property
                         $val = array_var($value, 'type') . '|' . array_var($value, 'street') . '|' . array_var($value, 'city') . '|' . array_var($value, 'state') . '|' . array_var($value, 'country') . '|' . array_var($value, 'zip_code');
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                         $custom_property_value = new CustomPropertyValue();
                         $custom_property_value->setObjectId($object->getId());
                         $custom_property_value->setCustomPropertyId($id);
                         $custom_property_value->setValue($val);
                         $custom_property_value->save();
                     } else {
                         //Save multiple values
                         CustomPropertyValues::deleteCustomPropertyValues($object->getId(), $id);
                         foreach ($value as &$val) {
                             if (is_array($val)) {
                                 // CP type == table
                                 $str_val = '';
                                 foreach ($val as $col_val) {
                                     $col_val = str_replace("|", "\\|", $col_val);
                                     $str_val .= ($str_val == '' ? '' : '|') . $col_val;
                                 }
                                 $val = $str_val;
                             }
                             if ($val != '') {
                                 $custom_property_value = new CustomPropertyValue();
                                 $custom_property_value->setObjectId($object->getId());
                                 $custom_property_value->setCustomPropertyId($id);
                                 $custom_property_value->setValue($val);
                                 $custom_property_value->save();
                             }
                         }
                     }
                 } else {
                     if ($custom_property->getType() == 'boolean') {
                         $value = isset($value);
                     }
                     $cpv = CustomPropertyValues::getCustomPropertyValue($object->getId(), $id);
                     if ($cpv instanceof CustomPropertyValue) {
                         $custom_property_value = $cpv;
                     } else {
                         $custom_property_value = new CustomPropertyValue();
                         $custom_property_value->setObjectId($object->getId());
                         $custom_property_value->setCustomPropertyId($id);
                     }
                     $custom_property_value->setValue($value);
                     $custom_property_value->save();
                 }
                 //Add to searchable objects
                 if ($object->isSearchable() && ($custom_property->getType() == 'text' || $custom_property->getType() == 'list' || $custom_property->getType() == 'numeric')) {
                     $name = str_replace("'", "\\'", $custom_property->getName());
                     if (is_array($value)) {
                         $value = implode(', ', $value);
                     }
                     $value = str_replace("'", "\\'", $value);
                     $sql = "INSERT INTO " . TABLE_PREFIX . "searchable_objects (rel_object_id, column_name, content)\r\n\t\t\t\t\t\tVALUES ('" . $object->getId() . "', '" . $name . "', '" . $value . "')\r\n\t\t\t\t\t\tON DUPLICATE KEY UPDATE content='" . $value . "'";
                     DB::execute($sql);
                 }
             }
         }
     }
     //Save the key - value pair custom properties (object_properties table)
     $object->clearObjectProperties();
     $names = array_var($_POST, 'custom_prop_names');
     $values = array_var($_POST, 'custom_prop_values');
     if (!is_array($names)) {
         return;
     }
     for ($i = 0; $i < count($names); $i++) {
         $name = trim($names[$i]);
         $value = trim($values[$i]);
         if ($name != '' && $value != '') {
             $property = new ObjectProperty();
             $property->setObject($object);
             $property->setPropertyName($name);
             $property->setPropertyValue($value);
             $property->save();
             if ($object->isSearchable()) {
                 $object->addPropertyToSearchableObject($property);
             }
         }
     }
 }
 /**
  * Set value of 'name' field
  *
  * @access public   
  * @param string $value
  * @return boolean
  */
 function setName($value)
 {
     $value = remove_scripts($value);
     return $this->setColumnValue('name', $value);
 }
Exemplo n.º 10
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)) {
         // set layout for modal form
         if (array_var($_REQUEST, 'modal')) {
             $this->setLayout("json");
             tpl_assign('modal', true);
         }
         $webpage_data = array('url' => $webpage->getUrl(), 'name' => $webpage->getObjectName(), 'description' => $webpage->getDescription());
     }
     if (is_array(array_var($_POST, 'webpage'))) {
         foreach ($webpage_data as $k => &$v) {
             $v = remove_scripts($v);
         }
         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);
             $webpage->resetIsRead();
             DB::commit();
             ApplicationLogs::createLog($webpage, ApplicationLogs::ACTION_EDIT);
             flash_success(lang('success edit webpage', $webpage->getObjectName()));
             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");
         }
     }
     tpl_assign('webpage', $webpage);
     tpl_assign('webpage_data', $webpage_data);
 }
 function edit_custom_report()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $report_id = array_var($_GET, 'id');
     $report = Reports::getReport($report_id);
     if (!$report->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     if (is_array(array_var($_POST, 'report'))) {
         try {
             ajx_current("empty");
             $report_data = array_var($_POST, 'report');
             foreach ($report_data as $k => &$v) {
                 $v = remove_scripts($v);
             }
             $member_ids = json_decode(array_var($_POST, 'members'));
             DB::beginWork();
             $report->setObjectName($report_data['name']);
             $report->setDescription($report_data['description']);
             $report->setReportObjectTypeId($report_data['report_object_type_id']);
             $report->setOrderBy($report_data['order_by']);
             $report->setIsOrderByAsc($report_data['order_by_asc'] == 'asc');
             $report->setIgnoreContext(array_var($report_data, 'ignore_context') == 'checked');
             $report->save();
             $conditions = array_var($_POST, 'conditions');
             if (!is_array($conditions)) {
                 $conditions = array();
             }
             foreach ($conditions as $condition) {
                 $newCondition = new ReportCondition();
                 if ($condition['id'] > 0) {
                     $newCondition = ReportConditions::getCondition($condition['id']);
                 }
                 if ($condition['deleted'] == "1") {
                     $newCondition->delete();
                     continue;
                 }
                 $newCondition->setReportId($report_id);
                 $custom_prop_id = isset($condition['custom_property_id']) ? $condition['custom_property_id'] : 0;
                 $newCondition->setCustomPropertyId($custom_prop_id);
                 $newCondition->setFieldName($condition['field_name']);
                 $newCondition->setCondition($condition['condition']);
                 if ($condition['field_type'] == 'boolean') {
                     $newCondition->setValue(isset($condition['value']) && $condition['value'] ? '1' : '0');
                 } else {
                     if ($condition['field_type'] == 'date') {
                         if (array_var($condition, 'value') == '') {
                             $newCondition->setValue('');
                         } else {
                             $dtFromWidget = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $condition['value']);
                             $newCondition->setValue(date("m/d/Y", $dtFromWidget->getTimestamp()));
                         }
                     } else {
                         $newCondition->setValue(isset($condition['value']) ? $condition['value'] : '');
                     }
                 }
                 $newCondition->setIsParametrizable(isset($condition['is_parametrizable']));
                 $newCondition->save();
             }
             ReportColumns::delete('report_id = ' . $report_id);
             $columns = array_var($_POST, 'columns');
             asort($columns);
             //sort the array by column order
             foreach ($columns as $column => $order) {
                 if ($order > 0) {
                     $newColumn = new ReportColumn();
                     $newColumn->setReportId($report_id);
                     if (is_numeric($column)) {
                         $newColumn->setCustomPropertyId($column);
                     } else {
                         $newColumn->setFieldName($column);
                     }
                     $newColumn->save();
                 }
             }
             $object_controller = new ObjectController();
             $object_controller->add_to_members($report, $member_ids);
             DB::commit();
             flash_success(lang('custom report updated'));
             ajx_current('back');
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     } else {
         $this->setTemplate('add_custom_report');
         tpl_assign('url', get_url('reporting', 'edit_custom_report', array('id' => $report_id)));
         if ($report instanceof Report) {
             tpl_assign('id', $report_id);
             $report_data = array('name' => $report->getObjectName(), 'description' => $report->getDescription(), 'report_object_type_id' => $report->getReportObjectTypeId(), 'order_by' => $report->getOrderBy(), 'order_by_asc' => $report->getIsOrderByAsc(), 'ignore_context' => $report->getIgnoreContext());
             tpl_assign('report_data', $report_data);
             $conditions = ReportConditions::getAllReportConditions($report_id);
             tpl_assign('conditions', $conditions);
             $columns = ReportColumns::getAllReportColumns($report_id);
             $colIds = array();
             foreach ($columns as $col) {
                 if ($col->getCustomPropertyId() > 0) {
                     $colIds[] = $col->getCustomPropertyId();
                 } else {
                     $colIds[] = $col->getFieldName();
                 }
             }
             tpl_assign('columns', $colIds);
         }
         $selected_type = $report->getReportObjectTypeId();
         $types = array(array("", lang("select one")));
         $object_types = ObjectTypes::getAvailableObjectTypes();
         $object_types[] = ObjectTypes::findByName('timeslot');
         Hook::fire('custom_reports_object_types', array('object_types' => $object_types), $object_types);
         foreach ($object_types as $ot) {
             $types[] = array($ot->getId(), lang($ot->getName()));
         }
         tpl_assign('object_types', $types);
         tpl_assign('selected_type', $selected_type);
         tpl_assign('object', $report);
         tpl_assign('allowed_columns', $this->get_allowed_columns($selected_type), true);
     }
 }