function get_custom_properties() { $object_type = array_var($_GET, 'object_type'); if ($object_type) { $cp = CustomProperties::getAllCustomPropertiesByObjectType($object_type); $customProperties = array(); foreach ($cp as $custom) { $prop = array(); $prop['id'] = $custom->getId(); $prop['name'] = $custom->getName(); $prop['object_type'] = $custom->getObjectTypeId(); $prop['description'] = $custom->getDescription(); $prop['type'] = $custom->getType(); $prop['values'] = $custom->getValues(); $prop['default_value'] = $custom->getDefaultValue(); $prop['required'] = $custom->getIsRequired(); $prop['multiple_values'] = $custom->getIsMultipleValues(); $prop['visible_by_default'] = $custom->getVisibleByDefault(); $prop['co_types'] = ''; //CustomPropertiesByCoType::instance()->getCoTypesIdsForCpCSV($custom->getId()); $customProperties[] = $prop; } ajx_current("empty"); ajx_extra_data(array("custom_properties" => $customProperties)); } }
/** * Return all report column names * * @param report_id * @return array */ static function getReportColumnNames($report_id) { $colNames = array(); $columns = self::findAll(array('conditions' => array("`report_id` = ?", $report_id))); // findAll foreach ($columns as $col) { if ($col->getCustomPropertyId() > 0) { $cp = CustomProperties::getCustomProperty($col->getCustomPropertyId()); if ($cp instanceof CustomProperty) { $colNames[] = $cp->getName(); } } else { $colNames[] = $col->getFieldName(); } } return $colNames; }
/** * Validate before save * * @access public * @param array $errors * @return null */ function validate(&$errors) { $cp = CustomProperties::getCustomProperty($this->getCustomPropertyId()); if($cp instanceof CustomProperty){ if($cp->getIsRequired() && ($this->getValue() == '')){ $errors[] = lang('custom property value required', $cp->getName()); } if($cp->getType() == 'numeric'){ if($cp->getIsMultipleValues()){ foreach(explode(',', $this->getValue()) as $value){ if($value != '' && !is_numeric($value)){ $errors[] = lang('value must be numeric', $cp->getName()); } } }else{ if($this->getValue() != '' && !is_numeric($this->getValue())){ $errors[] = lang('value must be numeric', $cp->getName()); } } } }//if } // validate
<div class="custom-properties"><?php require_javascript("og/CustomProperties.js"); $object_type_id = $_custom_properties_object instanceof TemplateTask ? ProjectTasks::instance()->getObjectTypeId() : $_custom_properties_object->getObjectTypeId(); $cps = CustomProperties::getAllCustomPropertiesByObjectType($object_type_id, $co_type); $ti = 0; if (!isset($genid)) { $genid = gen_id(); } if (!isset($startTi)) { $startTi = 10000; } if (count($cps) > 0) { $print_table_functions = false; foreach ($cps as $customProp) { if (!isset($required) || $required && ($customProp->getIsRequired() || $customProp->getVisibleByDefault()) || !$required && !($customProp->getIsRequired() || $customProp->getVisibleByDefault())) { $ti++; $cpv = CustomPropertyValues::getCustomPropertyValue($_custom_properties_object->getId(), $customProp->getId()); $default_value = $customProp->getDefaultValue(); if ($cpv instanceof CustomPropertyValue) { $default_value = $cpv->getValue(); } $name = 'object_custom_properties[' . $customProp->getId() . ']'; echo '<div style="margin-top:12px">'; if ($customProp->getType() == 'boolean') { echo checkbox_field($name, $default_value, array('tabindex' => $startTi + $ti, 'style' => 'margin-right:4px', 'id' => $genid . 'cp' . $customProp->getId())); } echo label_tag(clean($customProp->getName()), $genid . 'cp' . $customProp->getId(), $customProp->getIsRequired(), array('style' => 'display:inline'), $customProp->getType() == 'boolean' ? '' : ':'); echo '</div>'; switch ($customProp->getType()) { case 'text': case 'numeric':
/** * 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'); $customProps = CustomProperties::getAllCustomPropertiesByObjectType($object->getObjectTypeId()); //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 (is_array($obj_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) { $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $val); $newValues[] = $dtv->format("Y-m-d H:i:s"); } $value = $newValues; } else { $dtv = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $value); $value = $dtv->format("Y-m-d H:i:s"); } } //Save multiple values if (is_array($value)) { 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 != '') { if (strpos($val, ',')) { $val = str_replace(',', '|', $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 = $custom_property->getName(); $searchable_object = SearchableObjects::findOne(array("conditions" => "`rel_object_id` = " . $object->getId() . " AND `column_name` = '{$name}'")); if (!$searchable_object) { $searchable_object = new SearchableObject(); } if (is_array($value)) { $value = implode(', ', $value); } $searchable_object->setRelObjectId($object->getId()); $searchable_object->setColumnName($name); $searchable_object->setContent($value); $searchable_object->save(); } } } } }
/** * Prepares return object for a list of emails and messages * * @param array $totMsg * @param integer $start * @param integer $limit * @return array */ private function prepareObject($objects, $count, $start = 0, $attributes = null) { $object = array( "totalCount" => $count, "start" => $start, "contacts" => array() ); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(Contacts::instance()->getObjectTypeId()); for ($i = 0; $i < count($objects); $i++){ if (isset($objects[$i])){ $c= $objects[$i]; if ($c instanceof Contact && !$c->isCompany()){ $company = $c->getCompany(); $companyName = ''; if (!is_null($company)) $companyName= $company->getObjectName(); $personal_emails = $c->getContactEmails('personal'); $w_address = $c->getAddress('work'); $h_address = $c->getAddress('home'); $object["contacts"][$i] = array( "id" => $i, "ix" => $i, "object_id" => $c->getId(), "ot_id" => $c->getObjectTypeId(), "type" => 'contact', "name" => $c->getReverseDisplayName(), "email" => $c->getEmailAddress('personal',true), "companyId" => $c->getCompanyId(), "companyName" => $companyName, "website" => $c->getWebpage('personal') ? cleanUrl($c->getWebpageUrl('personal'), false) : '', "jobTitle" => $c->getJobTitle(), "department" => $c->getDepartment(), "email2" => !is_null($personal_emails) && isset($personal_emails[0]) ? $personal_emails[0]->getEmailAddress() : '', "email3" => !is_null($personal_emails) && isset($personal_emails[1]) ? $personal_emails[1]->getEmailAddress() : '', "workWebsite" => $c->getWebpage('work') ? cleanUrl($c->getWebpageUrl('work'), false) : '', "workAddress" => $w_address ? $c->getFullAddress($w_address) : '', "workPhone1" => $c->getPhone('work',true) ? $c->getPhoneNumber('work',true) : '', "workPhone2" => $c->getPhone('work') ? $c->getPhoneNumber('work') : '', "homeWebsite" => $c->getWebpage('personal') ? cleanUrl($c->getWebpageUrl('personal'), false) : '', "homeAddress" => $h_address ? $c->getFullAddress($h_address) : '', "homePhone1" => $c->getPhone('home',true) ? $c->getPhoneNumber('home',true) : '', "homePhone2" => $c->getPhone('home') ? $c->getPhoneNumber('home') : '', "mobilePhone" =>$c->getPhone('mobile') ? $c->getPhoneNumber('mobile') : '', "createdOn" => $c->getCreatedOn() instanceof DateTimeValue ? ($c->getCreatedOn()->isToday() ? format_time($c->getCreatedOn()) : format_datetime($c->getCreatedOn())) : '', "createdOn_today" => $c->getCreatedOn() instanceof DateTimeValue ? $c->getCreatedOn()->isToday() : 0, "createdBy" => $c->getCreatedByDisplayName(), "createdById" => $c->getCreatedById(), "updatedOn" => $c->getUpdatedOn() instanceof DateTimeValue ? ($c->getUpdatedOn()->isToday() ? format_time($c->getUpdatedOn()) : format_datetime($c->getUpdatedOn())) : '', "updatedOn_today" => $c->getUpdatedOn() instanceof DateTimeValue ? $c->getUpdatedOn()->isToday() : 0, "updatedBy" => $c->getUpdatedByDisplayName(), "updatedById" => $c->getUpdatedById(), "memPath" => json_encode($c->getMembersToDisplayPath()), "userType" => $c->getUserType(), ); } else if ($c instanceof Contact){ $w_address = $c->getAddress('work'); $object["contacts"][$i] = array( "id" => $i, "ix" => $i, "object_id" => $c->getId(), "ot_id" => $c->getObjectTypeId(), "type" => 'company', 'name' => $c->getObjectName(), 'email' => $c->getEmailAddress(), 'website' => $c->getWebpage('work') ? cleanUrl($c->getWebpageUrl('work'), false) : '', 'workPhone1' => $c->getPhone('work',true) ? $c->getPhoneNumber('work',true) : '', 'workPhone2' => $c->getPhone('fax',true) ? $c->getPhoneNumber('fax',true) : '', 'workAddress' => $w_address ? $c->getFullAddress($w_address) : '', "companyId" => $c->getId(), "companyName" => $c->getObjectName(), "jobTitle" => '', "department" => lang('company'), "email2" => '', "email3" => '', "workWebsite" => $c->getWebpage('work') ? cleanUrl($c->getWebpageUrl('work'), false) : '', "homeWebsite" => '', "homeAddress" => '', "homePhone1" => '', "homePhone2" => '', "mobilePhone" =>'', "createdOn" => $c->getCreatedOn() instanceof DateTimeValue ? ($c->getCreatedOn()->isToday() ? format_time($c->getCreatedOn()) : format_datetime($c->getCreatedOn())) : '', "createdOn_today" => $c->getCreatedOn() instanceof DateTimeValue ? $c->getCreatedOn()->isToday() : 0, "createdBy" => $c->getCreatedByDisplayName(), "createdById" => $c->getCreatedById(), "updatedOn" => $c->getUpdatedOn() instanceof DateTimeValue ? ($c->getUpdatedOn()->isToday() ? format_time($c->getUpdatedOn()) : format_datetime($c->getUpdatedOn())) : '', "updatedOn_today" => $c->getUpdatedOn() instanceof DateTimeValue ? $c->getUpdatedOn()->isToday() : 0, "updatedBy" => $c->getUpdatedByDisplayName(), "updatedById" => $c->getUpdatedById(), "memPath" => json_encode($c->getMembersToDisplayPath()), "contacts" => $c->getContactsByCompany(), "users" => $c->getUsersByCompany(), ); } foreach ($custom_properties as $cp) { $cp_value = CustomPropertyValues::getCustomPropertyValue($c->getId(), $cp->getId()); $object["contacts"][$i]['cp_'.$cp->getId()] = $cp_value instanceof CustomPropertyValue ? $cp_value->getValue() : ''; } } } return $object; }
<div> <?php echo label_tag(lang('display name'), 'profileFormDisplayName'); ?> <?php echo text_field('user[display_name]', array_var($user_data, 'display_name'), array('id' => 'profileFormDisplayName', 'tabindex' => '1000', 'class' => 'title')); ?> </div> <?php $categories = array(); Hook::fire('object_edit_categories', $object, $categories); ?> <?php $cps = CustomProperties::countHiddenCustomPropertiesByObjectType('Users'); ?> <div style="padding-top:5px"> <?php if (logged_user()->isAdministrator()) { ?> <a href="#" class="option" tabindex=1010 onclick="og.toggleAndBolden('<?php echo $genid; ?> update_profile_administrator_options',this)"><?php echo lang('administrator options'); ?> </a> - <?php }
</script> <!-- user type --> <div> <?php echo label_tag(lang('user type'), null, true); $permission_groups=array(); foreach($groups as $group){ $permission_groups[] = array($group->getId(), lang($group->getName())); } echo simple_select_box('user[type]', $permission_groups, null, array('onchange' => "og.addUserTypeChange('$genid', this.value)", 'tabindex' => "300")); ?> </div> <?php $categories = array(); Hook::fire('object_add_categories', $object, $categories); ?> <?php $cps = CustomProperties::countHiddenCustomPropertiesByObjectType(Contacts::getObjectTypeId()); ?> <div style="padding-top:5px"> <a href="#" class="option" onclick="og.toggleAndBolden('<?php echo $genid ?>add_user_advanced', this)"><?php echo lang('advanced') ?></a> - <a href="#" class="option" onclick="og.toggleAndBolden('<?php echo $genid ?>add_user_permissions', this)"><?php echo lang('permissions') ?></a> <?php if ($cps > 0) { ?> - <a href="#" class="option <?php echo $visible_cps>0 ? 'bold' : ''?>" onclick="og.toggleAndBolden('<?php echo $genid ?>add_custom_properties_div',this)"><?php echo lang('custom properties') ?></a> <?php } ?> <?php foreach ($categories as $category) { ?> - <a href="#" class="option" onclick="og.toggleAndBolden('<?php echo $genid . $category['name'] ?>', this)"><?php echo lang($category['name'])?></a> <?php } ?> </div> </div> <div class="adminSeparator"></div> <div class="adminMainBlock">
<?php require_javascript('og/modules/addMessageForm.js'); $genid = gen_id(); $object = $company; if ($company->isNew()) { $form_action = get_url('contact', 'add_company'); } else { $form_action = $company->getEditUrl(); } $renderContext = has_context_to_render($company->manager()->getObjectTypeId()); $visible_cps = CustomProperties::countVisibleCustomPropertiesByObjectType($object->getObjectTypeId()); ?> <form onsubmit="return og.handleMemberChooserSubmit('<?php echo $genid; ?> ', <?php echo $company->manager()->getObjectTypeId(); ?> );"style="height:100%;background-color:white" class="internalForm" action="<?php echo $form_action; ?> " method="post"> <div class="adminAddCompany"> <div class="adminHeader"> <div class="adminHeaderUpperRow"> <div class="adminTitle"><table style="width:535px"><tr><td> <?php echo $company->isNew() ? lang('new company') : lang('edit company');
//for normal properties //currently disabled as at the moment the only columns that can be added are custom properties $value = format_value_to_print_task($task->getColumnValue($i), $task->getColumnType($i)); ?> <td style="padding:4px;max-width:250px;<?php echo $isAlt ? 'background-color:#F2F2F2' : ''; ?> "><?php echo $value; ?> </td><?php } else { //for custom properties $values = CustomPropertyValues::getCustomPropertyValue($task->getId(), $i); if ($values != null) { $cp = CustomProperties::getCustomProperty($i); $value = format_value_to_print_task($values->getValue(), $cp->getOgType()); ?> <td style="padding:4px;max-width:250px;<?php echo $isAlt ? 'background-color:#F2F2F2' : ''; ?> "><?php echo $value; ?> </td><?php } else { ?> <td style="padding:4px;max-width:250px;<?php echo $isAlt ? 'background-color:#F2F2F2' : ''; ?> "><?php
private function get_report_column_types($report_id) { $col_types = array(); $report = Reports::getReport($report_id); $model = $report->getObjectType(); $manager = new $model(); $columns = ReportColumns::getAllReportColumns($report_id); foreach ($columns as $col) { $cp_id = $col->getCustomPropertyId(); if ($cp_id == 0) { $col_types[$col->getFieldName()] = $manager->getColumnType($col->getFieldName()); } else { $cp = CustomProperties::getCustomProperty($cp_id); if ($cp) { $col_types[$cp->getName()] = $cp->getOgType(); } } } return $col_types; }
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; }
function list_all() { ajx_current("empty"); $context = active_context() ; $start = array_var($_GET, 'start', 0); $limit = array_var($_GET, 'limit', config_option('files_per_page')); $order = array_var($_GET, 'sort'); if ($order == "updatedOn" || $order == "updated" || $order == "date" || $order == "dateUpdated") $order = "updated_on"; $order_dir = array_var($_GET, 'dir'); $page = (integer) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); if (array_var($_GET,'action') == 'delete') { $ids = explode(',', array_var($_GET, 'webpages')); $succ = 0; $err = 0; foreach ($ids as $id) { $web_page = ProjectWebpages::findById($id); if (isset($web_page) && $web_page->canDelete(logged_user())) { try{ DB::beginWork(); $web_page->trash(); ApplicationLogs::createLog($web_page, ApplicationLogs::ACTION_TRASH); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success delete objects", $succ)); } if ($err > 0) { flash_error(lang("error delete objects", $err)); } } else if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $webpage = ProjectWebpages::findById($id); try { $webpage->setIsRead(logged_user()->getId(),true); $succ++; } catch(Exception $e) { $err ++; } } if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } } else if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $webpage = ProjectWebpages::findById($id); try { $webpage->setIsRead(logged_user()->getId(),false); $succ++; } catch(Exception $e) { $err ++; } } if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else if (array_var($_GET,'action') == 'archive') { $ids = explode(',', array_var($_GET, 'webpages')); $succ = 0; $err = 0; foreach ($ids as $id) { $web_page = ProjectWebpages::findById($id); if (isset($web_page) && $web_page->canEdit(logged_user())) { try{ DB::beginWork(); $web_page->archive(); ApplicationLogs::createLog($web_page, ApplicationLogs::ACTION_ARCHIVE); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } if ($err > 0) { flash_error(lang("error archive objects", $err)); } } $res = ProjectWebpages::instance()->listing(array( "order" => $order , "order_dir" => $order_dir )); $object = array( "totalCount" => $res->total, "start" => $start, "webpages" => array() ); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectWebpages::instance()->getObjectTypeId()); if (isset($res->objects)) { $index = 0; $ids = array(); foreach ($res->objects as $w) { $ids[] = $w->getId(); $object["webpages"][$index] = array( "ix" => $index, "id" => $w->getId(), "object_id" => $w->getObjectId(), "ot_id" => $w->getObjectTypeId(), "name" => $w->getObjectName(), "description" => $w->getDescription(), "url" => $w->getUrl(), "updatedOn" => $w->getUpdatedOn() instanceof DateTimeValue ? ($w->getUpdatedOn()->isToday() ? format_time($w->getUpdatedOn()) : format_datetime($w->getUpdatedOn())) : '', "updatedOn_today" => $w->getUpdatedOn() instanceof DateTimeValue ? $w->getUpdatedOn()->isToday() : 0, "updatedBy" => $w->getUpdatedByDisplayName(), "updatedById" => $w->getUpdatedById(), "memPath" => json_encode($w->getMembersToDisplayPath()), ); foreach ($custom_properties as $cp) { $cp_value = CustomPropertyValues::getCustomPropertyValue($w->getId(), $cp->getId()); $object["webpages"][$index]['cp_'.$cp->getId()] = $cp_value instanceof CustomPropertyValue ? $cp_value->getValue() : ''; } $index++; } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach($object["webpages"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } } ajx_extra_data($object); }
<?php require_javascript("og/CustomProperties.js"); $cps = CustomProperties::getAllCustomPropertiesByObjectType($type, $co_type); $ti = 0; if (!isset($genid)) { $genid = gen_id(); } if (!isset($startTi)) { $startTi = 10000; } if (count($cps) > 0) { $print_table_functions = false; foreach ($cps as $customProp) { if (!isset($required) || $required && ($customProp->getIsRequired() || $customProp->getVisibleByDefault()) || !$required && !($customProp->getIsRequired() || $customProp->getVisibleByDefault())) { $ti++; $cpv = CustomPropertyValues::getCustomPropertyValue($_custom_properties_object->getId(), $customProp->getId()); $default_value = $customProp->getDefaultValue(); if ($cpv instanceof CustomPropertyValue) { $default_value = $cpv->getValue(); } $name = 'object_custom_properties[' . $customProp->getId() . ']'; echo '<div style="margin-top:6px">'; if ($customProp->getType() == 'boolean') { echo checkbox_field($name, $default_value, array('tabindex' => $startTi + $ti, 'style' => 'margin-right:4px', 'id' => $genid . 'cp' . $customProp->getName())); } echo label_tag(clean($customProp->getName()), $genid . 'cp' . $customProp->getName(), $customProp->getIsRequired(), array('style' => 'display:inline'), $customProp->getType() == 'boolean' ? '' : ':'); if ($customProp->getDescription() != '') { echo '<span class="desc" style="margin-left:10px">- ' . clean($customProp->getDescription()) . '</span>'; } echo '</div>';
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if(isset($this) && instance_of($this, 'CustomProperties')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return CustomProperties::instance()->paginate($arguments, $items_per_page, $current_page); } // if } // paginate
private function get_allowed_columns($object_type) { $fields = array(); if(isset($object_type)){ $customProperties = CustomProperties::getAllCustomPropertiesByObjectType($object_type); $objectFields = array(); foreach($customProperties as $cp){ if ($cp->getType() == 'table') continue; $fields[] = array('id' => $cp->getId(), 'name' => $cp->getName(), 'type' => $cp->getType(), 'values' => $cp->getValues(), 'multiple' => $cp->getIsMultipleValues()); } $ot = ObjectTypes::findById($object_type); eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();"); $objectColumns = $managerInstance->getColumns(); $objectFields = array(); $objectColumns = array_diff($objectColumns, $managerInstance->getSystemColumns()); foreach($objectColumns as $column){ $objectFields[$column] = $managerInstance->getColumnType($column); } $common_columns = Objects::instance()->getColumns(false); $common_columns = array_diff_key($common_columns, array_flip($managerInstance->getSystemColumns())); $objectFields = array_merge($objectFields, $common_columns); foreach($objectFields as $name => $type){ if($type == DATA_TYPE_FLOAT || $type == DATA_TYPE_INTEGER){ $type = 'numeric'; }else if($type == DATA_TYPE_STRING){ $type = 'text'; }else if($type == DATA_TYPE_BOOLEAN){ $type = 'boolean'; }else if($type == DATA_TYPE_DATE || $type == DATA_TYPE_DATETIME){ $type = 'date'; } $field_name = Localization::instance()->lang('field '.$ot->getHandlerClass().' '.$name); if (is_null($field_name)) $field_name = lang('field Objects '.$name); $fields[] = array('id' => $name, 'name' => $field_name, 'type' => $type); } $externalFields = $managerInstance->getExternalColumns(); foreach($externalFields as $extField){ $field_name = Localization::instance()->lang('field '.$ot->getHandlerClass().' '.$extField); if (is_null($field_name)) $field_name = lang('field Objects '.$extField); $fields[] = array('id' => $extField, 'name' => $field_name, 'type' => 'external', 'multiple' => 0); } } usort($fields, array(&$this, 'compare_FieldName')); return $fields; }
/** * List custom properties * * @access public * @param void * @return null */ function custom_properties() { if (!can_manage_configuration(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $object_types = ObjectTypes::instance()->findAll(array("conditions" => "`type` IN ('content_object') AND `name` <> 'template_task' AND name <> 'template_milestone' AND `name` <> 'file revision'", "order" => "name")); $ordered_object_types = array(); foreach ($object_types as $ot) { $ordered_object_types[$ot->getId()] = lang($ot->getName()); } asort($ordered_object_types, SORT_STRING); $select_options = array('<option value="" selected>' . lang('select one') . '</option>'); foreach ($ordered_object_types as $k => $v) { $select_options[] = '<option value="' . $k . '">' . $v . '</option>'; } tpl_assign('object_types', $select_options); $custom_properties = array_var($_POST, 'custom_properties'); $obj_type_id = array_var($_POST, 'objectType'); $delete = 0; if (is_array($custom_properties)) { try { DB::beginWork(); foreach ($custom_properties as $id => $data) { $new_cp = null; if ($data['id'] != '') { $new_cp = CustomProperties::getCustomProperty($data['id']); } if ($new_cp == null) { $new_cp = new CustomProperty(); } if ($data['deleted'] == "1") { $delete = $delete + 1; if (!$new_cp->isNew()) { $new_cp->delete(); } continue; } $new_cp->setObjectTypeId($obj_type_id); $new_cp->setName($data['name']); $new_cp->setType($data['type']); $new_cp->setDescription($data['description']); if ($data['type'] == 'list') { $values = array(); $list = explode(",", $data['values']); foreach ($list as $l) { $values[] = trim($l); } $value = implode(",", $values); $new_cp->setValues($value); } else { $new_cp->setValues($data['values']); } if ($data['type'] == 'boolean') { $new_cp->setDefaultValue(isset($data['default_value_boolean'])); } else { $new_cp->setDefaultValue($data['default_value']); } $new_cp->setIsRequired(isset($data['required'])); $new_cp->setIsMultipleValues(isset($data['multiple_values'])); $new_cp->setOrder($data['order'] - $delete); $new_cp->setVisibleByDefault(isset($data['visible_by_default'])); $new_cp->save(); if (is_array(array_var($data, 'applyto'))) { $applyto = array_var($data, 'applyto'); foreach ($applyto as $co_type => $value) { if ($value == 'true') { if (!CustomPropertiesByCoType::findById(array('co_type_id' => $co_type, 'cp_id' => $new_cp->getId()))) { $obj = new CustomPropertyByCoType(); $obj->setCoTypeId($co_type); $obj->setCpId($new_cp->getId()); $obj->save(); } } else { $obj = CustomPropertiesByCoType::findById(array('co_type_id' => $co_type, 'cp_id' => $new_cp->getId())); if ($obj) { $obj->delete(); } } } } } DB::commit(); flash_success(lang('custom properties updated')); ajx_current('back'); } catch (Exception $ex) { DB::rollback(); flash_error($ex->getMessage()); } } }
function list_files() { ajx_current("empty"); // get query parameters $start = (int) array_var($_GET, 'start'); $limit = (int) array_var($_GET, 'limit'); if (!$start) { $start = 0; } if (!$limit) { $limit = config_option('files_per_page'); } $order = array_var($_GET, 'sort'); $order_dir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $type = array_var($_GET, 'type'); $user = array_var($_GET, 'user'); // if there's an action to execute, do so if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canDelete(logged_user())) { try { DB::beginWork(); $file->trash(); DB::commit(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { if (!$file instanceof ProjectFile) { evt_add("popup", array('title' => lang('error'), 'message' => lang("file dnx"))); } else { if (!$file->canDelete(logged_user())) { evt_add("popup", array('title' => lang('error'), 'message' => lang("cannot delete file", $file->getObjectName()))); } } $err++; } } if ($succ > 0) { flash_success(lang("success delete files", $succ)); } else { flash_error(lang("error delete files", $err)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(), true); $succ++; } catch (Exception $e) { $err++; } // try } //for if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(), false); $succ++; } catch (Exception $e) { $err++; } // try } //for if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else { if (array_var($_GET, 'action') == 'zip_add') { $this->zip_add(); } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canEdit(logged_user())) { try { DB::beginWork(); $file->archive(); DB::commit(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } else { flash_error(lang("error archive objects", $err)); } } } } } } Hook::fire('classify_action', null, $ret); $join_params = null; $select_columns = null; $extra_conditions = ""; if (strpos($order, 'p_') == 1) { $cpId = substr($order, 3); $order = 'customProp'; } if ($order == ProjectFiles::ORDER_BY_POSTTIME) { $order = '`created_on`'; } else { if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) { $order = '`updated_on`'; } else { if ($order == ProjectFiles::ORDER_BY_SIZE) { $order = '`jt`.`filesize`'; $join_params = array('table' => ProjectFileRevisions::instance()->getTableName(), 'jt_field' => 'file_id', 'e_field' => 'object_id'); $extra_conditions .= " AND `jt`.`object_id` = (SELECT max(`x`.`object_id`) FROM " . TABLE_PREFIX . "project_file_revisions `x` WHERE `x`.`file_id` = `e`.`object_id`)"; } else { if ($order == 'customProp') { $order = 'IF(ISNULL(jt.value),1,0),jt.value'; $join_params['join_type'] = "LEFT "; $join_params['table'] = "" . TABLE_PREFIX . "custom_property_values"; $join_params['jt_field'] = "object_id"; $join_params['e_field'] = "object_id"; $join_params['on_extra'] = "AND custom_property_id = " . $cpId; $extra_conditions .= " AND ( custom_property_id = " . $cpId . " OR custom_property_id IS NULL)"; $select_columns = array("DISTINCT o.*", "e.*"); } else { $order = '`name`'; } } } } // if $extra_conditions .= $hide_private ? 'AND `is_visible` = 1' : ''; // filter attachments of other people if not filtering $tmp_mids = array(); foreach (active_context() as $selection) { if ($selection instanceof Member) { $d = $selection->getDimension(); if ($d instanceof Dimension && $d->getIsManageable()) { $tmp_mids[] = $selection->getId(); } } } if (count($tmp_mids) == 0) { if (Plugins::instance()->isActivePlugin('mail')) { $extra_conditions .= " AND IF(e.mail_id=0, true, EXISTS (SELECT mac.contact_id FROM " . TABLE_PREFIX . "mail_account_contacts mac \r\n\t\t\t\t\tWHERE mac.contact_id=o.created_by_id AND mac.account_id=(SELECT mc.account_id FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id=e.mail_id)))"; } } Hook::fire("listing_extra_conditions", null, $extra_conditions); $only_count_result = array_var($_GET, 'only_result', false); $context = active_context(); $objects = ProjectFiles::instance()->listing(array("order" => $order, "order_dir" => $order_dir, "extra_conditions" => $extra_conditions, "show_only_member_objects" => user_config_option('show_only_member_files'), 'count_results' => false, 'only_count_results' => $only_count_result, "join_params" => $join_params, "start" => $start, "limit" => $limit, "select_columns" => $select_columns)); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId()); // prepare response object $listing = array("totalCount" => $objects->total, "start" => $start, "objType" => ProjectFiles::instance()->getObjectTypeId(), "files" => array()); if (is_array($objects->objects)) { $index = 0; $ids = array(); foreach ($objects->objects as $o) { $coName = ""; $coId = $o->getCheckedOutById(); if ($coId != 0) { if ($coId == logged_user()->getId()) { $coName = "self"; } else { $coUser = Contacts::findById($coId); if ($coUser instanceof Contact) { $coName = $coUser->getObjectName(); } else { $coName = ""; } } } if ($o->isMP3()) { $songname = $o->getProperty("songname"); $artist = $o->getProperty("songartist"); $album = $o->getProperty("songalbum"); $track = $o->getProperty("songtrack"); $year = $o->getProperty("songyear"); $duration = $o->getProperty("songduration"); $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId())); } else { $songInfo = array(); } $ids[] = $o->getId(); $values = array("id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "ot_id" => $o->getObjectTypeId(), "name" => $o->getObjectName(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "createdBy" => clean($o->getCreatedByDisplayName()), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn()) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => clean($o->getUpdatedByDisplayName()), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn()) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => format_filesize($o->getFileSize()), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "memPath" => json_encode($o->getMembersIdsToDisplayPath()), "genid" => gen_id()); if ($o->isMP3()) { $values['isMP3'] = true; } Hook::fire('add_classification_value', $o, $values); foreach ($custom_properties as $cp) { $values['cp_' . $cp->getId()] = get_custom_property_value_for_listing($cp, $o); } $listing["files"][] = $values; } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach ($listing["files"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } ajx_extra_data($listing); tpl_assign("listing", $listing); } else { throw new Error("Not array", $code); } }
<?php require_javascript("og/CustomProperties.js"); $cps = CustomProperties::getAllCustomPropertiesByObjectType($_custom_properties_object->getObjectTypeId(), $co_type); $ti = 0; if (!isset($genid)) { $genid = gen_id(); } if (!isset($startTi)) { $startTi = 10000; } if (count($cps) > 0) { $print_table_functions = false; foreach ($cps as $customProp) { if (!isset($required) || $required && ($customProp->getIsRequired() || $customProp->getVisibleByDefault()) || !$required && !($customProp->getIsRequired() || $customProp->getVisibleByDefault())) { $ti++; $cpv = CustomPropertyValues::getCustomPropertyValue($_custom_properties_object->getId(), $customProp->getId()); $default_value = $customProp->getDefaultValue(); if ($cpv instanceof CustomPropertyValue) { $default_value = $cpv->getValue(); } $name = 'object_custom_properties[' . $customProp->getId() . ']'; echo '<div style="margin-top:6px">'; if ($customProp->getType() == 'boolean') { echo checkbox_field($name, $default_value, array('tabindex' => $startTi + $ti, 'style' => 'margin-right:4px', 'id' => $genid . 'cp' . $customProp->getId())); } echo label_tag(clean($customProp->getName()), $genid . 'cp' . $customProp->getId(), $customProp->getIsRequired(), array('style' => 'display:inline'), $customProp->getType() == 'boolean' ? '' : ':'); if ($customProp->getDescription() != '') { echo '<span class="desc"> - ' . clean($customProp->getDescription()) . '</span>'; } echo '</div>';
?> </b></td> <td style="text-align:center;padding:0 10px 10px 10px;"><b><?php echo lang('condition'); ?> </b></td> <td style="text-align:center;padding:0 10px 10px 10px;"><b><?php echo lang('value'); ?> </b></td> </tr> <?php foreach ($conditions as $condition) { if ($condition->getCustomPropertyId() > 0) { $cp = CustomProperties::getCustomProperty($condition->getCustomPropertyId()); if (!$cp) { continue; } } $tiCount++; ?> <tr style='height:30px;'> <?php if ($condition->getCustomPropertyId() > 0) { $name = clean($cp->getName()); } else { if ($condition->getFieldName() != 'workspace' && $condition->getFieldName() != 'tag') { $name = lang('field ' . $model . ' ' . $condition->getFieldName()); } else { $name = lang($condition->getFieldName());
<table><tr><th></th><th><?php echo $import_type == 'contact' ? lang('contact fields') : lang('company fields'); ?> </th><th><?php echo lang('fields from file'); ?> </th></tr> <?php if ($import_type == 'contact') { $contact_fields = Contacts::getContactFieldNames(); } else { $contact_fields = Contacts::getCompanyFieldNames(); } $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(Contacts::instance()->getObjectTypeId()); +($isAlt = false); $i = 0; $label_w = $label_h = $label_o = false; foreach ($contact_fields as $c_field => $c_label) { if (str_starts_with($c_field, 'contact[w') && !$label_w) { ?> <tr><td colspan="3" style="text-align:center;"><b><?php echo lang('work'); ?> </b></td></tr> <?php $label_w = true; } else { if (str_starts_with($c_field, 'contact[h') && !$label_h) { ?> <tr><td colspan="3" style="text-align:center;"><b><?php
private function checkRequiredCustomPropsBeforeSave($custom_props) { $errors = array(); if (is_array($custom_props)) { foreach ($custom_props as $id => $value) { $cp = CustomProperties::findById($id); if (!$cp) { continue; } if ($cp->getIsRequired() && $value == '') { $errors[] = lang('custom property value required', $cp->getName()); } } } return $errors; }
static function removeDuplicateRows($rows) { $duplicateIds = array(); foreach ($rows as $row) { if (!isset($duplicateIds[$row['id']])) { $duplicateIds[$row['id']] = 0; } $duplicateIds[$row['id']]++; } foreach ($duplicateIds as $id => $count) { if ($count < 2) { unset($duplicateIds[$id]); } } $duplicateIds = array_keys($duplicateIds); foreach ($rows as $row) { if (in_array($row['id'], $duplicateIds)) { foreach ($row as $col => $value) { $cp = CustomProperties::getCustomProperty($col); if ($cp instanceof CustomProperty && $cp->getIsMultipleValues()) { } } } } return $rows; }
<?php if ($task->hasComments() != '') { ?> <br/> <?php echo render_object_comments_for_print($task, $task->getViewUrl()); } // if ?> <br/> <?php $has_custom_properties = CustomProperties::countAllCustomPropertiesByObjectType($task->getObjectTypeId()) > 0; if ($has_custom_properties) { ?> <p><b><?php echo lang('custom properties'); ?> :</b></p> <div style="margin-left:14px;padding:6px;border:1px solid #AAA"> <?php echo str_replace(lang('custom properties'), "", render_custom_properties($task)); ?> </div> <?php } ?>
/** * Return manager instance * * @access protected * @param void * @return CustomProperty */ function manager() { if (!$this->manager instanceof CustomProperties) { $this->manager = CustomProperties::instance(); } return $this->manager; }
/** * Prepares return object for a list of emails and messages * * @param array $totMsg * @param integer $start * @param integer $limit * @return array */ private function prepareObject($emails, $start, $limit, $total, $attributes = null) { $object = array("totalCount" => intval($total), "start" => $start, "messages" => array()); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(MailContents::instance()->getObjectTypeId()); $i = 0; foreach ($emails as $email) { if ($email instanceof MailContent) { $properties = $this->getMailProperties($email, $i); $object["messages"][$i] = $properties; } foreach ($custom_properties as $cp) { $object["messages"][$i]['cp_' . $cp->getId()] = get_custom_property_value_for_listing($cp, $email); } $i++; } //set columns to show for this folder if (isset($attributes)) { $string = user_config_option("folder_" . $attributes["stateType"] . "_columns"); $columns = explode(",", $string); foreach ($columns as $col) { $object["folder_columns"][] = $col; } $object["folder_name"] = $attributes["stateType"]; //if you want to add a column add their name here too $object["folder_columns_all"] = array("from", "to", "subject", "account", "date", "folder", "actions"); } return $object; }
/** * Return custom property value count for the object * * @param $object_id * @return array */ static function getCustomPropertyValueCount($object) { return count(self::findAll(array('conditions' => array("`object_id` = ? AND `custom_property_id` in (SELECT `id` FROM " . CustomProperties::instance()->getTableName(true) . " where `object_type_id` = ?)", $object->getObjectId(), $object->getObjectTypeId())))); // findAll }
/** * Prepares return object for a list of emails and messages * * @param array $totMsg * @param integer $start * @param integer $limit * @return array */ private function prepareObject($totMsg, $start, $limit, $total) { $object = array("totalCount" => $total, "start" => $start, "messages" => array()); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectMessages::instance()->getObjectTypeId()); $ids = array(); for ($i = 0; $i < $limit; $i++) { if (isset($totMsg[$i])) { $msg = $totMsg[$i]; if ($msg instanceof ProjectMessage) { $text = $msg->getText(); if (strlen($text) > 100) { $text = substr_utf($text, 0, 100) . "..."; } $object["messages"][$i] = array("id" => $i, "ix" => $i, "object_id" => $msg->getId(), "ot_id" => $msg->getObjectTypeId(), "type" => $msg->getObjectTypeName(), "name" => $msg->getObjectName(), "text" => html_to_text($text), "date" => $msg->getUpdatedOn() instanceof DateTimeValue ? $msg->getUpdatedOn()->isToday() ? format_time($msg->getUpdatedOn()) : format_datetime($msg->getUpdatedOn()) : '', "is_today" => $msg->getUpdatedOn() instanceof DateTimeValue ? $msg->getUpdatedOn()->isToday() : 0, "userId" => $msg->getCreatedById(), "userName" => $msg->getCreatedByDisplayName(), "updaterId" => $msg->getUpdatedById() ? $msg->getUpdatedById() : $msg->getCreatedById(), "updaterName" => $msg->getUpdatedById() ? $msg->getUpdatedByDisplayName() : $msg->getCreatedByDisplayName(), "memPath" => json_encode($msg->getMembersIdsToDisplayPath())); $ids[] = $msg->getId(); foreach ($custom_properties as $cp) { $object["messages"][$i]['cp_' . $cp->getId()] = get_custom_property_value_for_listing($cp, $msg); } } } } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach ($object["messages"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } return $object; }
function list_files() { ajx_current("empty"); // get query parameters $start = (integer)array_var($_GET,'start'); $limit = (integer)array_var($_GET,'limit'); if (! $start) { $start = 0; } if (! $limit) { $limit = config_option('files_per_page'); } $order = array_var($_GET,'sort'); $order_dir = array_var($_GET,'dir'); $page = (integer) ($start / $limit)+1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $type = array_var($_GET,'type'); $user = array_var($_GET,'user'); // if there's an action to execute, do so if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canDelete(logged_user())) { try{ DB::beginWork(); $file->trash(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success delete files", $succ)); } else { flash_error(lang("error delete files", $err)); } } else if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(),true); $succ++; } catch(Exception $e) { $err ++; } // try }//for if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } }else if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(),false); $succ++; } catch(Exception $e) { $err ++; } // try }//for if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else if (array_var($_GET, 'action') == 'zip_add') { $this->zip_add(); } else if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canEdit(logged_user())) { try{ DB::beginWork(); $file->archive(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } else { flash_error(lang("error archive objects", $err)); } } Hook::fire('classify_action', null, $ret); $join_params = null; if ($order == ProjectFiles::ORDER_BY_POSTTIME) { $order = '`created_on`'; } else if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) { $order = '`updated_on`'; } else if ($order == ProjectFiles::ORDER_BY_SIZE) { $order = '`jt`.`filesize`'; $join_params = array( 'table' => ProjectFileRevisions::instance()->getTableName(), 'jt_field' => 'object_id', 'j_sub_q' => "SELECT max(`x`.`object_id`) FROM ".ProjectFileRevisions::instance()->getTableName()." `x` WHERE `x`.`file_id` = `e`.`object_id`" ); } else { $order = '`name`'; } // if $extra_conditions = $hide_private ? 'AND `is_visible` = 1' : ''; $context = active_context(); $objects = ProjectFiles::instance()->listing(array( "order"=>$order, "order_dir" => $order_dir, "extra_conditions"=> $extra_conditions, "join_params"=> $join_params, "start"=> $start, "limit"=> $limit )); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId()); // prepare response object $listing = array( "totalCount" => $objects->total, "start" => $start, "objType" => ProjectFiles::instance()->getObjectTypeId(), "files" => array(), ); if (is_array($objects->objects)) { $index = 0; $ids = array(); foreach ($objects->objects as $o) { $coName = ""; $coId = $o->getCheckedOutById(); if ($coId != 0) { if ($coId == logged_user()->getId()) { $coName = "self"; } else { $coUser = Contacts::findById($coId); if ($coUser instanceof Contact) { $coName = $coUser->getUsername(); } else { $coName = ""; } } } if ($o->isMP3()) { $songname = $o->getProperty("songname"); $artist = $o->getProperty("songartist"); $album = $o->getProperty("songalbum"); $track = $o->getProperty("songtrack"); $year = $o->getProperty("songyear"); $duration = $o->getProperty("songduration"); $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId())); } else { $songInfo = array(); } $ids[] = $o->getId(); $values = array( "id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "ot_id" => $o->getObjectTypeId(), "name" => $o->getObjectName(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "createdBy" => clean($o->getCreatedByDisplayName()), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? ($o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn())) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => clean($o->getUpdatedByDisplayName()), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? ($o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn())) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => format_filesize($o->getFileSize()), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "memPath" => json_encode($o->getMembersToDisplayPath()), ); if ($o->isMP3()) { $values['isMP3'] = true; } Hook::fire('add_classification_value', $o, $values); foreach ($custom_properties as $cp) { $cp_value = CustomPropertyValues::getCustomPropertyValue($o->getId(), $cp->getId()); $values['cp_'.$cp->getId()] = $cp_value instanceof CustomPropertyValue ? $cp_value->getValue() : ''; } $listing["files"][] = $values; } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach($listing["files"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } ajx_extra_data($listing); tpl_assign("listing", $listing); }else{ throw new Error("Not array", $code); } }
$cpvCount = CustomPropertyValues::getCustomPropertyValueCount($__properties_object); if ((!is_array($properties) || count($properties) == 0) && $cpvCount == 0) { return ""; } ?> <div class="commentsTitle"><?php echo lang('custom properties'); ?> </div> <?php if ($cpvCount > 0) { ?> <table class="og-custom-properties"> <?php $alt = true; $cps = CustomProperties::getAllCustomPropertiesByObjectType($__properties_object->getObjectTypeId()); foreach ($cps as $customProp) { $cpv = CustomPropertyValues::getCustomPropertyValue($__properties_object->getId(), $customProp->getId()); if ($cpv instanceof CustomPropertyValue && ($customProp->getIsRequired() || $cpv->getValue() != '')) { $alt = !$alt; ?> <tr class="<?php echo $alt ? 'altRow' : ''; ?> "> <td class="name" title="<?php echo clean($customProp->getName()); ?> "><?php echo clean($customProp->getName()); ?>