Ejemplo n.º 1
0
 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));
     }
 }
 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);
         }
         if (!array_var($_REQUEST, 'noaddcol')) {
             Hook::fire('custom_reports_additional_columns', null, $fields);
         }
     }
     usort($fields, array(&$this, 'compare_FieldName'));
     return $fields;
 }
Ejemplo n.º 3
0
	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);
	}
 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;
 }
Ejemplo n.º 5
0
 function cloneTask($copy_status = false)
 {
     $new_task = new ProjectTask();
     $new_task->setParentId($this->getParentId());
     $new_task->setTitle($this->getTitle());
     $new_task->setText($this->getText());
     $new_task->setAssignedToCompanyId($this->getAssignedToCompanyId());
     $new_task->setAssignedToUserId($this->getAssignedToUserId());
     $new_task->setAssignedOn($this->getAssignedOn());
     $new_task->setAssignedById($this->getAssignedById());
     $new_task->setTimeEstimate($this->getTimeEstimate());
     $new_task->setStartedOn($this->getStartedOn());
     $new_task->setStartedById($this->getStartedById());
     $new_task->setPriority($this->getPriority());
     $new_task->setState($this->getState());
     $new_task->setOrder($this->getOrder());
     $new_task->setMilestoneId($this->getMilestoneId());
     $new_task->setIsPrivate($this->getIsPrivate());
     $new_task->setIsTemplate($this->getIsTemplate());
     $new_task->setFromTemplateId($this->getFromTemplateId());
     if ($this->getDueDate() instanceof DateTimeValue) {
         $new_task->setDueDate(new DateTimeValue($this->getDueDate()->getTimestamp()));
     }
     if ($this->getStartDate() instanceof DateTimeValue) {
         $new_task->setStartDate(new DateTimeValue($this->getStartDate()->getTimestamp()));
     }
     if ($copy_status) {
         $new_task->setCompletedById($this->getCompletedById());
         $new_task->setCompletedOn($this->getCompletedOn());
     }
     $new_task->save();
     $new_task->setTagsFromCSV(implode(",", $this->getTagNames()));
     foreach ($this->getWorkspaces() as $ws) {
         $new_task->addToWorkspace($ws);
     }
     if (is_array($this->getAllLinkedObjects())) {
         foreach ($this->getAllLinkedObjects() as $lo) {
             $new_task->linkObject($lo);
         }
     }
     $sub_tasks = $this->getAllSubTasks();
     foreach ($sub_tasks as $st) {
         if ($st->getParentId() == $this->getId()) {
             $new_st = $st->cloneTask($copy_status);
             if ($copy_status) {
                 $new_st->setCompletedById($st->getCompletedById());
                 $new_st->setCompletedOn($st->getCompletedOn());
                 $new_st->save();
             }
             $new_task->attachTask($new_st);
         }
     }
     foreach ($this->getAllComments() as $com) {
         $new_com = new Comment();
         $new_com->setAuthorEmail($com->getAuthorEmail());
         $new_com->setAuthorName($com->getAuthorName());
         $new_com->setAuthorHomepage($com->getAuthorHomepage());
         $new_com->setCreatedById($com->getCreatedById());
         $new_com->setCreatedOn($com->getCreatedOn());
         $new_com->setUpdatedById($com->getUpdatedById());
         $new_com->setUpdatedOn($com->getUpdatedOn());
         $new_com->setIsAnonymous($com->getIsAnonymous());
         $new_com->setIsPrivate($com->getIsPrivate());
         $new_com->setText($com->getText());
         $new_com->setRelObjectId($new_task->getId());
         $new_com->setRelObjectManager("ProjectTasks");
         $new_com->save();
     }
     $_POST['subscribers'] = array();
     foreach ($this->getSubscribers() as $sub) {
         $_POST['subscribers']["user_" . $sub->getId()] = "checked";
     }
     $obj_controller = new ObjectController();
     $obj_controller->add_subscribers($new_task);
     foreach ($this->getCustomProperties() as $prop) {
         $new_prop = new ObjectProperty();
         $new_prop->setRelObjectId($new_task->getId());
         $new_prop->setRelObjectManager($prop->getRelObjectManager());
         $new_prop->setPropertyName($prop->getPropertyName());
         $new_prop->setPropertyValue($prop->getPropertyValue());
         $new_prop->save();
     }
     $custom_props = CustomProperties::getAllCustomPropertiesByObjectType("ProjectTasks");
     foreach ($custom_props as $c_prop) {
         $values = CustomPropertyValues::getCustomPropertyValues($this->getId(), $c_prop->getId());
         if (is_array($values)) {
             foreach ($values as $val) {
                 $cp = new CustomPropertyValue();
                 $cp->setObjectId($new_task->getId());
                 $cp->setCustomPropertyId($val->getCustomPropertyId());
                 $cp->setValue($val->getValue());
                 $cp->save();
             }
         }
     }
     $reminders = ObjectReminders::getByObject($this);
     foreach ($reminders as $reminder) {
         $copy_reminder = new ObjectReminder();
         $copy_reminder->setContext($reminder->getContext());
         $reminder_date = $new_task->getColumnValue($reminder->getContext());
         if ($reminder_date instanceof DateTimeValue) {
             $reminder_date = new DateTimeValue($reminder_date->getTimestamp());
             $reminder_date->add('m', -$reminder->getMinutesBefore());
         }
         $copy_reminder->setDate($reminder_date);
         $copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
         $copy_reminder->setObject($new_task);
         $copy_reminder->setType($reminder->getType());
         $copy_reminder->setUserId($reminder->getUserId());
         $copy_reminder->save();
     }
     return $new_task;
 }
Ejemplo n.º 6
0
	
	<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 
Ejemplo n.º 7
0
<?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>';
 /**
  * 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;
 }
Ejemplo n.º 9
0
	/**
	 * 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,//(integer)min(array(count($totMsg) - (count($totMsg) % $limit),$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) {
				$cp_value = CustomPropertyValues::getCustomPropertyValue($email->getId(), $cp->getId());
				$object["messages"][$i]['cp_'.$cp->getId()] = $cp_value instanceof CustomPropertyValue ? $cp_value->getValue() : '';
			}
			$i++;
		}
		return $object;
	}
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * 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);
             }
         }
     }
 }
Ejemplo n.º 12
0
/**
 * Copies related data from an object to another (members, linked_objects, custom_properties, subscribers, reminders and comments)
 * @param $object: Original object to copy data
 * @param $copy: Object to be modified with the data of the $orignal object
 * @param $options: set which type of data will not be copied
 */
function copy_additional_object_data($object, &$copy, $options = array())
{
    if (!$object instanceof ContentDataObject || !$copy instanceof ContentDataObject) {
        // if not valid objects return
        return;
    }
    $copy_members = !array_var($options, 'dont_copy_members');
    $copy_linked_objects = !array_var($options, 'dont_copy_linked_objects');
    $copy_custom_properties = !array_var($options, 'dont_copy_custom_properties');
    $copy_subscribers = !array_var($options, 'dont_copy_subscribers');
    $copy_reminders = !array_var($options, 'dont_copy_reminders');
    $copy_comments = !array_var($options, 'dont_copy_comments');
    $controller = new ObjectController();
    // copy members
    if ($copy_members) {
        $object_members = $object->getMembers();
        $copy->addToMembers($object_members);
        Hook::fire('after_add_to_members', $copy, $object_members);
        $copy->addToSharingTable();
    }
    // copy linked objects
    if ($copy_linked_objects) {
        $copy->copyLinkedObjectsFrom($object);
    }
    // copy custom properties
    if ($copy_custom_properties) {
        // custom properties defined in "settings"
        $cp_object_type_id = $object->getObjectTypeId();
        if ($object instanceof TemplateTask || $object instanceof TemplateMilestone) {
            $cp_object_type_id = $copy->getObjectTypeId();
        }
        $custom_props = CustomProperties::getAllCustomPropertiesByObjectType($cp_object_type_id);
        foreach ($custom_props as $c_prop) {
            $values = CustomPropertyValues::getCustomPropertyValues($object->getId(), $c_prop->getId());
            if (is_array($values)) {
                foreach ($values as $val) {
                    $cp = new CustomPropertyValue();
                    $cp->setObjectId($copy->getId());
                    $cp->setCustomPropertyId($val->getCustomPropertyId());
                    $cp->setValue($val->getValue());
                    $cp->save();
                }
            }
        }
        // object properties (key-value)
        $copy->copyCustomPropertiesFrom($object);
    }
    // copy subscribers
    if ($copy_subscribers) {
        $subscribers_array = array();
        foreach ($object->getSubscriberIds() as $user_id) {
            $subscribers_array["user_" . $user_id] = "1";
        }
        $controller->add_subscribers($copy, $subscribers_array);
    }
    // copy reminders
    if ($copy_reminders) {
        $reminders = ObjectReminders::getByObject($object);
        foreach ($reminders as $reminder) {
            $copy_reminder = new ObjectReminder();
            $copy_reminder->setContext($reminder->getContext());
            $reminder_date = $copy->getColumnValue($reminder->getContext());
            if ($reminder_date instanceof DateTimeValue) {
                $reminder_date = new DateTimeValue($reminder_date->getTimestamp());
                $reminder_date->add('m', -$reminder->getMinutesBefore());
            }
            $copy_reminder->setDate($reminder_date);
            $copy_reminder->setMinutesBefore($reminder->getMinutesBefore());
            $copy_reminder->setObject($copy);
            $copy_reminder->setType($reminder->getType());
            $copy_reminder->setUserId($reminder->getUserId());
            $copy_reminder->save();
        }
    }
    // copy comments
    if ($copy_comments) {
        foreach ($object->getAllComments() as $com) {
            $new_com = new Comment();
            $new_com->setAuthorEmail($com->getAuthorEmail());
            $new_com->setAuthorName($com->getAuthorName());
            $new_com->setAuthorHomepage($com->getAuthorHomepage());
            $new_com->setCreatedById($com->getCreatedById());
            $new_com->setCreatedOn($com->getCreatedOn());
            $new_com->setUpdatedById($com->getUpdatedById());
            $new_com->setUpdatedOn($com->getUpdatedOn());
            $new_com->setText($com->getText());
            $new_com->setRelObjectId($copy->getId());
            $new_com->save();
        }
    }
}
Ejemplo n.º 13
0
$cpvCount = CustomPropertyValues::getCustomPropertyValueCount($__properties_object->getId(), get_class($__properties_object->manager()));
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(get_class($__properties_object->manager()));
    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(truncate($customProp->getName(), 20));
            ?>
Ejemplo n.º 14
0
 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);
     }
 }
Ejemplo n.º 15
0
$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());
            ?>
Ejemplo n.º 16
0
	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);			
		}
	}
Ejemplo n.º 17
0
 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);
         }
         //if Object type is person
         $objType = ObjectTypes::findByName('contact');
         if ($objType instanceof ObjectType) {
             if ($object_type == $objType->getId()) {
                 $fields[] = array('id' => 'email_address', 'name' => lang('email address'), 'type' => 'text');
                 $fields[] = array('id' => 'phone_number', 'name' => lang('phone number'), 'type' => 'text');
                 $fields[] = array('id' => 'web_url', 'name' => lang('web pages'), 'type' => 'text');
                 $fields[] = array('id' => 'im_value', 'name' => lang('instant messengers'), 'type' => 'text');
                 $fields[] = array('id' => 'address', 'name' => lang('address'), 'type' => 'text');
             }
         }
     }
     usort($fields, array(&$this, 'compare_FieldName'));
     return $fields;
 }
Ejemplo n.º 18
0
 /**
  * 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();
                 }
             }
         }
     }
 }
<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':
 private function get_allowed_columns($object_type, $includeWsAndTag = false)
 {
     $fields = array();
     if (isset($object_type)) {
         $customProperties = CustomProperties::getAllCustomPropertiesByObjectType($object_type);
         $objectFields = array();
         foreach ($customProperties as $cp) {
             $fields[] = array('id' => $cp->getId(), 'name' => $cp->getName(), 'type' => $cp->getType(), 'values' => $cp->getValues(), 'multiple' => $cp->getIsMultipleValues());
         }
         eval('$managerInstance = ' . $object_type . "::instance();");
         $objectColumns = $managerInstance->getColumns();
         $objectFields = array();
         $objectColumns = array_diff($objectColumns, $managerInstance->getSystemColumns());
         foreach ($objectColumns as $column) {
             $objectFields[$column] = $managerInstance->getColumnType($column);
         }
         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';
                         }
                     }
                 }
             }
             $fields[] = array('id' => $name, 'name' => lang('field ' . $object_type . ' ' . $name), 'type' => $type);
         }
         $externalFields = $managerInstance->getExternalColumns();
         foreach ($externalFields as $extField) {
             $fields[] = array('id' => $extField, 'name' => lang('field ' . $object_type . ' ' . $extField), 'type' => 'external', 'multiple' => 0);
         }
         // Workspace and Tags
         if ($includeWsAndTag && $object_type != 'Projects' && $object_type != 'Users') {
             $fields[] = array('id' => 'workspace', 'name' => lang('workspace'), 'type' => 'external');
             $fields[] = array('id' => 'tag', 'name' => lang('tag'), 'type' => 'external');
         }
     }
     usort($fields, array(&$this, 'compare_FieldName'));
     return $fields;
 }
<?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>';
Ejemplo n.º 22
0
	/**
	 * 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;
	}
 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);
         if (class_exists($ot->getHandlerClass())) {
             eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();");
             $objectColumns = $managerInstance->getColumns();
         } else {
             $objectColumns = array();
         }
         $objectFields = array();
         if (class_exists($ot->getHandlerClass())) {
             $objectColumns = array_diff($objectColumns, $managerInstance->getSystemColumns());
             foreach ($objectColumns as $column) {
                 $objectFields[$column] = $managerInstance->getColumnType($column);
             }
         }
         $common_columns = Objects::instance()->getColumns(false);
         if (class_exists($ot->getHandlerClass())) {
             $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 = array('id' => $name, 'name' => $field_name, 'type' => $type);
             $task_ot = ObjectTypes::findByName('task');
             if ($task_ot instanceof ObjectType && $object_type == $task_ot->getId() && $name == 'priority') {
                 $fields_array = array('id' => 'priority', 'name' => lang('priority'), 'type' => 'list', 'values' => '100,200,300,400');
             }
             $fields[] = $fields_array;
         }
         if (class_exists($ot->getHandlerClass())) {
             $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);
             }
         }
         //if Object type is person
         $contact_ot = ObjectTypes::findByName('contact');
         if ($contact_ot instanceof ObjectType && $object_type == $contact_ot->getId()) {
             $fields[] = array('id' => 'is_user', 'name' => lang('is_user'), 'type' => 'boolean');
             $fields[] = array('id' => 'email_address', 'name' => lang('email address'), 'type' => 'text');
             $fields[] = array('id' => 'mobile_phone', 'name' => lang('mobile phone'), 'type' => 'text');
             $fields[] = array('id' => 'work_phone', 'name' => lang('work phone'), 'type' => 'text');
             $fields[] = array('id' => 'home_phone', 'name' => lang('home phone'), 'type' => 'text');
             $fields[] = array('id' => 'im_values', 'name' => lang('instant messaging'), 'type' => 'text');
             $fields[] = array('id' => 'personal_webpage', 'name' => lang('personal_webpage'), 'type' => 'text');
             $fields[] = array('id' => 'work_webpage', 'name' => lang('work_webpage'), 'type' => 'text');
             $fields[] = array('id' => 'other_webpage', 'name' => lang('other_webpage'), 'type' => 'text');
             $fields[] = array('id' => 'home_address', 'name' => lang('home_address'), 'type' => 'text');
             $fields[] = array('id' => 'work_address', 'name' => lang('work_address'), 'type' => 'text');
             $fields[] = array('id' => 'other_address', 'name' => lang('other_address'), 'type' => 'text');
         }
         if (!array_var($_REQUEST, 'noaddcol')) {
             Hook::fire('custom_reports_additional_columns', array('object_type' => $ot), $fields);
         }
     }
     usort($fields, array(&$this, 'compare_FieldName'));
     return $fields;
 }