function getObjectTypeName() { if (!$this->object_type) { $this->object_type = ObjectTypes::findById($this->getObjectTypeId()); } return $this->object_type->getName(); }
</span></legend> <div id="<?php echo $genid; ?> dimension<?php echo $dimension->getId(); ?> " style="display:none;"> <?php $dim_members = array_var($members, $dimension->getId()); $alt = true; if (is_array($dim_members)) { foreach ($dim_members as $mem) { $alt = !$alt; $indent = 16 * $mem->getDepth(); $ot = ObjectTypes::findById($mem->getObjectTypeId()); $ot_name = $ot instanceof ObjectType ? lang($ot->getName()) : $mem->getName(); ?> <div style="margin-left:<?php echo $indent; ?> px;width:<?php echo 800 - $indent; ?> px;" id="abm-members-item-container-<?php echo $mem->getId(); ?> " class="<?php echo $mem->getArchivedById() > 0 ? "member-item-archived" : ""; echo $alt ? " edit-mem-alt" : "";
function quick_config_filter_activity(){ $this->setLayout('empty'); $submited_values = array_var($_POST, 'filter'); $members = array_var($_GET, 'members'); tpl_assign('members', array_var($_GET, 'members')); $member_name = lang('view'); $obj_member = Members::findById($members); if($obj_member){ $type_obj = ObjectTypes::findById($obj_member->getObjectTypeId()); if($obj_member){ $member_name = lang($type_obj->getName()); } } tpl_assign('dim_name', $member_name); $filters_default = ContactConfigOptions::getFilterActivity(); $filters = ContactConfigOptionValues::getFilterActivityMember($filters_default->getId(),$members); if(!$filters){ $filters = ContactConfigOptions::getFilterActivity(); $filter_value = $filters->getDefaultValue(); tpl_assign('id', $filters->getId()); }else{ $filter_value = $filters->getValue(); tpl_assign('id', ''); } $filters_def = explode(",",$filter_value); // if($filters_def[0] == 1){ // tpl_assign('checked_dimension_yes', 'checked="checked"'); // }else{ // tpl_assign('checked_dimension_no', 'checked="checked"'); // } if($filters_def[1] == 1){ tpl_assign('timeslot', 'checked="checked"'); }else{ tpl_assign('timeslot', ''); } tpl_assign('show', $filters_def[2]); // if($filters_def[3] == 1){ // tpl_assign('checked_view_downloads_yes', 'checked="checked"'); // }else{ // tpl_assign('checked_view_downloads_no', 'checked="checked"'); // } if(is_array($submited_values)) { $members = array_var($submited_values,"members"); $new_value = array_var($submited_values,"dimension",0) . "," . array_var($submited_values,"timeslot",0) . "," . array_var($submited_values,"show",10). "," . array_var($submited_values,"view_downloads",0); $filters_default = ContactConfigOptions::getFilterActivity(); if(array_var($submited_values,"apply_everywhere") == 1){ $filters_default->setDefaultValue($new_value); $filters_default->save(); $filters = ContactConfigOptionValues::getFilterActivityDelete($filters_default->getId()); }else{ $filters = ContactConfigOptionValues::getFilterActivityMember($filters_default->getId(),$members); // update cache if available if (GlobalCache::isAvailable()) { GlobalCache::delete('user_config_option_'.logged_user()->getId().'_'.$filters_default->getName()."_".$members); } if(!$filters){ $filter_opt = new ContactConfigOptionValue(); $filter_opt->setOptionId($filters_default->getId()); $filter_opt->setContactId(logged_user()->getId()); $filter_opt->setValue($new_value); $filter_opt->setMemberId($members); $filter_opt->save(); }else{ $filters->setValue($new_value); $filters->save(); } evt_add("user preference changed", array('name' => $filters_default->getName()."_".$members, 'value' => $new_value)); } ajx_current("reload"); } }
if (!isset($dimensions_info[$dimension->getName()])) { $dimensions_info[$dimension->getName()] = array('members' => array(), 'icon' => $member->getIconClass()); } if (!isset($dimensions_info[$dimension->getName()]['icon'])) { $dimensions_info[$dimension->getName()]['icon'] = $member->getIconClass(); } $parents = array_reverse($member->getAllParentMembersInHierarchy(true)); foreach ($parents as $p) { $dimensions_info[$dimension->getName()]['members'][$p->getId()] = array('p' => $p->getParentMemberId(), 'name' => $p->getName(), 'ot' => $p->getObjectTypeId(), 'color' => $p->getMemberColor()); } } foreach ($dimensions_info as &$dim_info) { if (!isset($dim_info['icon'])) { $dots = DimensionObjectTypes::findAll(array('conditions' => 'dimension_id = ' . $dim_info['id'])); if (count($dots) > 0) { $ot = ObjectTypes::findById($dots[0]->getObjectTypeId()); if ($ot instanceof ObjectType) { $dim_info['icon'] = $ot->getIconClass(); } } } } if (count($dimensions_info) > 0) { ksort($dimensions_info, SORT_STRING); ?> <div class="commentsTitle"><?php echo lang('related to'); ?> </div> <div style="padding-bottom: 10px;"> <?php
/** * Execute a report and return results * * @param $id * @param $params * * @return array */ static function executeReport($id, $params, $order_by_col = '', $order_by_asc = true, $offset = 0, $limit = 50, $to_print = false) { if (is_null(active_context())) { CompanyWebsite::instance()->setContext(build_context_array(array_var($_REQUEST, 'context'))); } $results = array(); $report = self::getReport($id); $show_archived = false; if ($report instanceof Report) { $conditionsFields = ReportConditions::getAllReportConditionsForFields($id); $conditionsCp = ReportConditions::getAllReportConditionsForCustomProperties($id); $ot = ObjectTypes::findById($report->getReportObjectTypeId()); $table = $ot->getTableName(); if ($ot->getType() == 'dimension_object' || $ot->getType() == 'dimension_group') { $hook_parameters = array('report' => $report, 'params' => $params, 'order_by_col' => $order_by_col, 'order_by_asc' => $order_by_asc, 'offset' => $offset, 'limit' => $limit, 'to_print' => $to_print); $report_result = null; Hook::fire('replace_execute_report_function', $hook_parameters, $report_result); if ($report_result) { return $report_result; } } eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();"); eval('$item_class = ' . $ot->getHandlerClass() . '::instance()->getItemClass(); $object = new $item_class();'); $order_by = ''; if (is_object($params)) { $params = get_object_vars($params); } $report_columns = ReportColumns::getAllReportColumns($id); $allConditions = ""; $contact_extra_columns = self::get_extra_contact_columns(); if (count($conditionsFields) > 0) { foreach ($conditionsFields as $condField) { if ($condField->getFieldName() == "archived_on") { $show_archived = true; } $skip_condition = false; $model = $ot->getHandlerClass(); $model_instance = new $model(); $col_type = $model_instance->getColumnType($condField->getFieldName()); $allConditions .= ' AND '; $dateFormat = 'm/d/Y'; if (isset($params[$condField->getId()])) { $value = $params[$condField->getId()]; if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) { $dateFormat = user_config_option('date_format'); } } else { $value = $condField->getValue(); } if ($ot->getHandlerClass() == 'Contacts' && in_array($condField->getFieldName(), $contact_extra_columns)) { $allConditions .= self::get_extra_contact_column_condition($condField->getFieldName(), $condField->getCondition(), $value); } else { if ($value == '' && $condField->getIsParametrizable()) { $skip_condition = true; } if (!$skip_condition) { $field_name = $condField->getFieldName(); if (in_array($condField->getFieldName(), Objects::getColumns())) { $field_name = 'o`.`' . $condField->getFieldName(); } if ($condField->getCondition() == 'like' || $condField->getCondition() == 'not like') { $value = '%' . $value . '%'; } if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) { if ($value == date_format_tip($dateFormat)) { $value = EMPTY_DATE; } else { $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value); $value = $dtValue->format('Y-m-d'); } } if ($condField->getCondition() != '%') { if ($col_type == DATA_TYPE_INTEGER || $col_type == DATA_TYPE_FLOAT) { $allConditions .= '`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value); } else { if ($condField->getCondition() == '=' || $condField->getCondition() == '<=' || $condField->getCondition() == '>=') { if ($col_type == DATA_TYPE_DATETIME || $col_type == DATA_TYPE_DATE) { $equal = 'datediff(' . DB::escape($value) . ', `' . $field_name . '`)=0'; } else { $equal = '`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value); } switch ($condField->getCondition()) { case '=': $allConditions .= $equal; break; case '<=': case '>=': $allConditions .= '(`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value) . ' OR ' . $equal . ') '; break; } } else { $allConditions .= '`' . $field_name . '` ' . $condField->getCondition() . ' ' . DB::escape($value); } } } else { $allConditions .= '`' . $field_name . '` like ' . DB::escape("%{$value}"); } } else { $allConditions .= ' true'; } } } } if (count($conditionsCp) > 0) { $dateFormat = user_config_option('date_format'); $date_format_tip = date_format_tip($dateFormat); foreach ($conditionsCp as $condCp) { $cp = CustomProperties::getCustomProperty($condCp->getCustomPropertyId()); $skip_condition = false; if (isset($params[$condCp->getId() . "_" . $cp->getName()])) { $value = $params[$condCp->getId() . "_" . $cp->getName()]; } else { $value = $condCp->getValue(); } if ($value == '' && $condCp->getIsParametrizable()) { $skip_condition = true; } if (!$skip_condition) { $current_condition = ' AND '; $current_condition .= 'o.id IN ( SELECT object_id as id FROM ' . TABLE_PREFIX . 'custom_property_values cpv WHERE '; $current_condition .= ' cpv.custom_property_id = ' . $condCp->getCustomPropertyId(); $fieldType = $object->getColumnType($condCp->getFieldName()); if ($condCp->getCondition() == 'like' || $condCp->getCondition() == 'not like') { $value = '%' . $value . '%'; } if ($cp->getType() == 'date') { if ($value == $date_format_tip) { continue; } $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value); $value = $dtValue->format('Y-m-d H:i:s'); } if ($condCp->getCondition() != '%') { if ($cp->getType() == 'numeric') { $current_condition .= ' AND cpv.value ' . $condCp->getCondition() . ' ' . DB::escape($value); } else { if ($cp->getType() == 'boolean') { $current_condition .= ' AND cpv.value ' . $condCp->getCondition() . ' ' . ($value ? '1' : '0'); if (!$value) { $current_condition .= ') OR o.id NOT IN (SELECT object_id as id FROM ' . TABLE_PREFIX . 'custom_property_values cpv2 WHERE cpv2.object_id=o.id AND cpv2.value=1 AND cpv2.custom_property_id = ' . $condCp->getCustomPropertyId(); } } else { $current_condition .= ' AND cpv.value ' . $condCp->getCondition() . ' ' . DB::escape($value); } } } else { $current_condition .= ' AND cpv.value like ' . DB::escape("%{$value}"); } $current_condition .= ')'; $allConditions .= $current_condition; } } } $select_columns = array('*'); $join_params = null; if ($order_by_col == '') { $order_by_col = $report->getOrderBy(); } if ($ot->getHandlerClass() == 'Contacts' && in_array($order_by_col, $contact_extra_columns)) { $join_params = self::get_extra_contact_column_order_by($order_by_col, $order_by_col, $select_columns); } $original_order_by_col = $order_by_col; if (in_array($order_by_col, self::$external_columns)) { $order_by_col = 'name_order'; $join_params = array('table' => Objects::instance()->getTableName(), 'jt_field' => 'id', 'e_field' => $original_order_by_col, 'join_type' => 'left'); $select_columns = array(); $tmp_cols = $managerInstance->getColumns(); foreach ($tmp_cols as $col) { $select_columns[] = "e.{$col}"; } $tmp_cols = Objects::instance()->getColumns(); foreach ($tmp_cols as $col) { $select_columns[] = "o.{$col}"; } $select_columns[] = 'jt.name as name_order'; } if ($order_by_asc == null) { $order_by_asc = $report->getIsOrderByAsc(); } if ($ot->getName() == 'task' && !SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) { $allConditions .= " AND assigned_to_contact_id = " . logged_user()->getId(); } if ($managerInstance) { if ($order_by_col == "order") { $order_by_col = "`{$order_by_col}`"; } $listing_parameters = array("select_columns" => $select_columns, "order" => "{$order_by_col}", "order_dir" => $order_by_asc ? "ASC" : "DESC", "extra_conditions" => $allConditions, "count_results" => true, "join_params" => $join_params); if ($limit > 0) { $listing_parameters["start"] = $offset; $listing_parameters["limit"] = $limit; } if ($show_archived) { $listing_parameters["archived"] = true; } $result = $managerInstance->listing($listing_parameters); } else { // TODO Performance Killer $result = ContentDataObjects::getContentObjects(active_context(), $ot, $order_by_col, $order_by_asc ? "ASC" : "DESC", $allConditions); } $objects = $result->objects; $totalResults = $result->total; $results['pagination'] = Reports::getReportPagination($id, $params, $original_order_by_col, $order_by_asc, $offset, $limit, $totalResults); $dimensions_cache = array(); foreach ($report_columns as $column) { if ($column->getCustomPropertyId() == 0) { $field = $column->getFieldName(); if (str_starts_with($field, 'dim_')) { $dim_id = str_replace("dim_", "", $field); $dimension = Dimensions::getDimensionById($dim_id); $dimensions_cache[$dim_id] = $dimension; $column_name = $dimension->getName(); $results['columns'][$field] = $column_name; $results['db_columns'][$column_name] = $field; } else { if ($managerInstance->columnExists($field) || Objects::instance()->columnExists($field)) { $column_name = Localization::instance()->lang('field ' . $ot->getHandlerClass() . ' ' . $field); if (is_null($column_name)) { $column_name = lang('field Objects ' . $field); } $results['columns'][$field] = $column_name; $results['db_columns'][$column_name] = $field; } else { if ($ot->getHandlerClass() == 'Contacts') { if (in_array($field, $contact_extra_columns)) { $results['columns'][$field] = lang($field); $results['db_columns'][lang($field)] = $field; } } else { if ($ot->getHandlerClass() == 'Timeslots') { if (in_array($field, array('time', 'billing'))) { $results['columns'][$field] = lang('field Objects ' . $field); $results['db_columns'][lang('field Objects ' . $field)] = $field; } } else { if ($ot->getHandlerClass() == 'MailContents') { if (in_array($field, array('to', 'cc', 'bcc', 'body_plain', 'body_html'))) { $results['columns'][$field] = lang('field Objects ' . $field); $results['db_columns'][lang('field Objects ' . $field)] = $field; } } } } } } } else { $results['columns'][$column->getCustomPropertyId()] = $column->getCustomPropertyId(); } } $report_rows = array(); foreach ($objects as &$object) { /* @var $object Object */ $obj_name = $object->getObjectName(); $icon_class = $object->getIconClass(); $row_values = array('object_type_id' => $object->getObjectTypeId()); if (!$to_print) { $row_values['link'] = '<a class="link-ico ' . $icon_class . '" title="' . clean($obj_name) . '" target="new" href="' . $object->getViewUrl() . '"> </a>'; } foreach ($report_columns as $column) { if ($column->getCustomPropertyId() == 0) { $field = $column->getFieldName(); if (str_starts_with($field, 'dim_')) { $dim_id = str_replace("dim_", "", $field); if (!array_var($dimensions_cache, $dim_id) instanceof Dimension) { $dimension = Dimensions::getDimensionById($dim_id); $dimensions_cache[$dim_id] = $dimension; } else { $dimension = array_var($dimensions_cache, $dim_id); } $om_object_id = $object instanceof Timeslot ? $object->getRelObjectId() : $object->getId(); $members = ObjectMembers::getMembersByObjectAndDimension($om_object_id, $dim_id, " AND om.is_optimization=0"); $value = ""; foreach ($members as $member) { /* @var $member Member */ $val = $member->getPath(); $val .= ($val == "" ? "" : "/") . $member->getName(); if ($value != "") { $val = " - {$val}"; } $value .= $val; } $row_values[$field] = $value; } else { if ($object instanceof Timeslot) { if ($field == 'id') { $value = $object->getObjectId(); } else { $value = $object->getColumnValue($field); // if it is a task column if (in_array($field, ProjectTasks::instance()->getColumns())) { $task = ProjectTasks::findById($object->getRelObjectId()); // if task exists if ($task instanceof ProjectTask) { $value = $task->getColumnValue($field); // if it is an external task column if (in_array($field, ProjectTasks::instance()->getExternalColumns())) { $value = self::instance()->getExternalColumnValue($field, $value, ProjectTasks::instance()); } else { // if is a date then use format if (ProjectTasks::instance()->getColumnType($field) == DATA_TYPE_DATETIME && $value instanceof DateTimeValue) { $value = format_value_to_print($field, $value->toMySQL(), DATA_TYPE_DATETIME, $report->getReportObjectTypeId()); } } } $results['columns'][$field] = lang('field ProjectTasks ' . $field); $results['db_columns'][lang('field ProjectTasks ' . $field)] = $field; } } } else { $value = $object->getColumnValue($field); } if ($value instanceof DateTimeValue) { $dateFormat = user_config_option('date_format'); Hook::fire("custom_property_date_format", null, $dateFormat); $tz = logged_user()->getTimezone(); if ($object instanceof ProjectTask) { if ($field == 'due_date' && !$object->getUseDueTime() || $field == 'start_date' && !$object->getUseStartTime()) { $dateFormat = user_config_option('date_format'); $tz = 0; } } $value = format_date($value, $dateFormat, $tz * 3600); } if (in_array($field, $managerInstance->getExternalColumns())) { if ($object instanceof Timeslot && $field == 'time') { $lastStop = $object->getEndTime() != null ? $object->getEndTime() : ($object->isPaused() ? $object->getPausedOn() : DateTimeValueLib::now()); $seconds = $lastStop->getTimestamp() - $object->getStartTime()->getTimestamp(); $hours = number_format($seconds / 3600, 2, ',', '.'); $value = $hours; //$value = DateTimeValue::FormatTimeDiff($object->getStartTime(), $lastStop, "hm", 60, $object->getSubtract()); } else { if ($object instanceof Timeslot && $field == 'billing') { $value = config_option('currency_code', '$') . ' ' . $object->getFixedBilling(); } else { $value = self::instance()->getExternalColumnValue($field, $value, $managerInstance); } } } else { if ($field != 'link') { //$value = html_to_text(html_entity_decode($value)); if ($object->getColumnType($field) == DATA_TYPE_STRING) { // change html block end tags and brs to \n, then remove all other html tags, then replace \n with <br>, to remove all styles and keep the enters $value = str_replace(array("</div>", "</p>", "<br>", "<br />", "<br/>"), "\n", $value); $value = nl2br(strip_tags($value)); } } } if (self::isReportColumnEmail($value)) { if (logged_user()->hasMailAccounts()) { $value = '<a class="internalLink" href="' . get_url('mail', 'add_mail', array('to' => clean($value))) . '">' . clean($value) . '</a></div>'; } else { $value = '<a class="internalLink" target="_self" href="mailto:' . clean($value) . '">' . clean($value) . '</a></div>'; } } $row_values[$field] = $value; if ($ot->getHandlerClass() == 'Contacts') { if ($managerInstance instanceof Contacts) { $contact = Contacts::findOne(array("conditions" => "object_id = " . $object->getId())); if ($field == "email_address") { $row_values[$field] = $contact->getEmailAddress(); } if ($field == "is_user") { $row_values[$field] = $contact->getUserType() > 0 && !$contact->getIsCompany(); } if ($field == "im_values") { $str = ""; foreach ($contact->getAllImValues() as $type => $value) { $str .= ($str == "" ? "" : " | ") . "{$type}: {$value}"; } $row_values[$field] = $str; } if (in_array($field, array("mobile_phone", "work_phone", "home_phone"))) { if ($field == "mobile_phone") { $row_values[$field] = $contact->getPhoneNumber('mobile', null, false); } else { if ($field == "work_phone") { $row_values[$field] = $contact->getPhoneNumber('work', null, false); } else { if ($field == "home_phone") { $row_values[$field] = $contact->getPhoneNumber('home', null, false); } } } } if (in_array($field, array("personal_webpage", "work_webpage", "other_webpage"))) { if ($field == "personal_webpage") { $row_values[$field] = $contact->getWebpageUrl('personal'); } else { if ($field == "work_webpage") { $row_values[$field] = $contact->getWebpageUrl('work'); } else { if ($field == "other_webpage") { $row_values[$field] = $contact->getWebpageUrl('other'); } } } } if (in_array($field, array("home_address", "work_address", "other_address"))) { if ($field == "home_address") { $row_values[$field] = $contact->getStringAddress('home'); } else { if ($field == "work_address") { $row_values[$field] = $contact->getStringAddress('work'); } else { if ($field == "other_address") { $row_values[$field] = $contact->getStringAddress('other'); } } } } } } else { if ($ot->getHandlerClass() == 'MailContents') { if (in_array($field, array('to', 'cc', 'bcc', 'body_plain', 'body_html'))) { $mail_data = MailDatas::findById($object->getId()); $row_values[$field] = $mail_data->getColumnValue($field); if ($field == "body_html") { if (class_exists("DOMDocument")) { $d = new DOMDocument(); $mock = new DOMDocument(); $d->loadHTML(remove_css_and_scripts($row_values[$field])); $body = $d->getElementsByTagName('body')->item(0); foreach ($body->childNodes as $child) { $mock->appendChild($mock->importNode($child, true)); } // if css is inside an html comment => remove it $row_values[$field] = preg_replace('/<!--(.*)-->/Uis', '', remove_css($row_values[$field])); } else { $row_values[$field] = preg_replace('/<!--(.*)-->/Uis', '', remove_css_and_scripts($row_values[$field])); } } } } } if (!$to_print && $field == "name") { $row_values[$field] = '<a target="new-' . $object->getId() . '" href="' . $object->getViewUrl() . '">' . $value . '</a>'; } } } else { $colCp = $column->getCustomPropertyId(); $cp = CustomProperties::getCustomProperty($colCp); if ($cp instanceof CustomProperty) { /* @var $cp CustomProperty */ $row_values[$cp->getName()] = get_custom_property_value_for_listing($cp, $object); $results['columns'][$colCp] = $cp->getName(); $results['db_columns'][$cp->getName()] = $colCp; } } } Hook::fire("report_row", $object, $row_values); $report_rows[] = $row_values; } if (!$to_print) { if (is_array($results['columns'])) { array_unshift($results['columns'], ''); } else { $results['columns'] = array(''); } Hook::fire("report_header", $ot, $results['columns']); } $results['rows'] = $report_rows; } return $results; }
</table> <?php }// if ?> </td></tr></table> </div> <?php if (count($task->getMembers()) > 0) { ?> <p><b> <!-- CONTEXTS --> <?php $contexts = array(); $members = $task->getMembers(); if(count($members)>0){ foreach ($members as $member){ $dim = $member->getDimension(); if($dim->getIsManageable()){ if ($dim->getCode() == "customer_project"){ $obj_type = ObjectTypes::findById($member->getObjectTypeId()); if ($obj_type instanceof ObjectType) { echo lang($dim->getCode()). ": "; echo $contexts[$dim->getCode()][$obj_type->getName()][]= '<span style="'.get_workspace_css_properties($member->getMemberColor()).'">'. $member->getName() .'</span>'; } }else{ echo lang($dim->getCode()). ": "; echo $contexts[$dim->getCode()][]= '<span style="'.get_workspace_css_properties($member->getMemberColor()).'">'. $member->getName() .'</span>'; } } } } ?> <!-- CONTEXTS --> </b></p> <?php } // if ?>
</div> </div> <div class="coInputSeparator"></div> <div class="coInputMainBlock"> <div style="width:600px;padding-bottom:20px"><?php echo $description ?></div> <table> <tr> <td style="padding:0 10px 10px 10px;"><span class="bold"><?php echo lang('field') ?></span></td> <td style="text-align:center;padding:0 10px 10px 10px;"><span class="bold"><?php echo lang('condition') ?></span></td> <td style="text-align:center;padding:0 10px 10px 10px;"><span class="bold"><?php echo lang('value') ?></span></td> </tr> <?php $ot = ObjectTypes::findById($model); $model = $ot->getHandlerClass(); foreach($conditions as $condition){ if($condition->getCustomPropertyId() > 0){ $cp = CustomProperties::getCustomProperty($condition->getCustomPropertyId()); $name = $cp->getName(); if (!$cp) continue; } else { $name = lang('field ' . $model . ' ' . $condition->getFieldName()); } $tiCount ++; ?> <tr style='height:30px;'> <?php $condId = $genid . 'rpcond' . $condition->getId(); if ($firstId == '') $firstId = $condId;
$ot = ObjectTypes::findById($member->getObjectTypeId()); $ot_name = lang($ot->getName()); if ($member->getArchivedById() == 0) { add_page_action(lang('archive'), "javascript:if(confirm('" . lang('confirm archive member', $ot_name) . "')) og.openLink('" . get_url('member', 'archive', array('id' => $member->getId())) . "');", 'ico-archive-obj'); } else { add_page_action(lang('unarchive'), "javascript:if(confirm('" . lang('confirm unarchive member', $ot_name) . "')) og.openLink('" . get_url('member', 'unarchive', array('id' => $member->getId())) . "');", 'ico-unarchive-obj'); } $delete_url = get_url('member', 'delete', array('id' => $member->getId(), 'start' => true)); add_page_action(lang('delete'), "javascript:og.deleteMember('" . $delete_url . "','" . $ot_name . "');", 'ico-delete'); } $form_title = $object_type_name ? ($member->isNew() ? lang('new') : lang('edit')) . strtolower(" {$object_type_name}") : lang('new member'); $new_member_text = $object_type_name ? ($member->isNew() ? lang('add') : lang('edit')) . strtolower(" {$object_type_name}") : lang('new member'); $categories = array(); Hook::fire('member_edit_categories', array('member' => $member, 'genid' => $genid), $categories); $has_custom_properties = count(MemberCustomProperties::getCustomPropertyIdsByObjectType($obj_type_sel)) > 0; $member_ot = ObjectTypes::findById($member->getObjectTypeId()); $dim_obj = null; if ($member_ot->getType() == 'dimension_object') { if (!$member->isNew()) { $dim_obj = Objects::findObject($member->getObjectId()); } else { if (class_exists($member_ot->getHandlerClass())) { eval('$ot_manager = ' . $member_ot->getHandlerClass() . '::instance();'); if (isset($ot_manager) && $ot_manager instanceof ContentDataObjects) { eval('$dim_obj = new ' . $ot_manager->getItemClass() . '();'); if ($dim_obj instanceof ContentDataObject) { $dim_obj->setNew(true); $dim_obj->setObjectTypeId($member->getObjectTypeId()); } } }
function permission_member_form_parameters($member = null) { if ($member) { $dim = $member->getDimension(); } elseif (array_var($_REQUEST, 'dim_id')) { $dim = Dimensions::getDimensionById(array_var($_REQUEST, 'dim_id')); } if (logged_user()->isMemberOfOwnerCompany()) { $companies = Contacts::findAll(array("conditions" => "is_company = 1", 'order' => 'name')); } else { $companies = array(owner_company()); if (logged_user()->getCompany() instanceof Contact) { $companies[] = logged_user()->getCompany(); } } $allowed_object_types = array(); $dim_obj_types = $dim->getAllowedObjectTypeContents(); foreach ($dim_obj_types as $dim_obj_type) { // To draw a row for each object type of the dimension if (!array_key_exists($dim_obj_type->getContentObjectTypeId(), $allowed_object_types) && (!$member || $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId())) { $allowed_object_types[$dim_obj_type->getContentObjectTypeId()] = ObjectTypes::findById($dim_obj_type->getContentObjectTypeId()); $allowed_object_types_json[] = $dim_obj_type->getContentObjectTypeId(); } } $permission_groups = array(); foreach ($companies as $company) { $users = $company->getUsersByCompany(); foreach ($users as $u) { $permission_groups[] = $u->getPermissionGroupId(); } } $no_company_users = Contacts::getAllUsers("AND `company_id` = 0", true); foreach ($no_company_users as $noc_user) { $permission_groups[] = $noc_user->getPermissionGroupId(); } $non_personal_groups = PermissionGroups::getNonRolePermissionGroups(); foreach ($non_personal_groups as $group) { $permission_groups[] = $group->getId(); } foreach ($permission_groups as $pg_id) { if ($dim->hasAllowAllForContact($pg_id)) { $member_permissions[$pg_id] = array(); foreach ($dim_obj_types as $dim_obj_type) { if ($member && $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId()) { $member_permissions[$pg_id][] = array('o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 1, 'd' => 1, 'r' => 1); } elseif (!$member) { // WHEN CREATING a new member dont allow any user $member_permissions[$pg_id][] = array('o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 0, 'd' => 0, 'r' => 0); } } } else { if (!$dim->deniesAllForContact($pg_id)) { $member_permissions[$pg_id] = array(); if ($member) { $mpgs = ContactMemberPermissions::findAll(array("conditions" => array("`permission_group_id` = ? AND `member_id` = ?", $pg_id, $member->getId()))); if (is_array($mpgs)) { foreach ($mpgs as $mpg) { $member_permissions[$mpg->getPermissionGroupId()][] = array('o' => $mpg->getObjectTypeId(), 'w' => $mpg->getCanWrite() ? 1 : 0, 'd' => $mpg->getCanDelete() ? 1 : 0, 'r' => 1); } } } } } } return array('member' => $member, 'allowed_object_types' => $allowed_object_types, 'allowed_object_types_json' => $allowed_object_types_json, 'permission_groups' => $permission_groups, 'member_permissions' => $member_permissions); }
function workEstimate(ProjectTask $task) { tpl_assign('task_assigned', $task); if (!$task->getAssignedTo() instanceof Contact) { return true; // not assigned to user } if (!is_valid_email($task->getAssignedTo()->getEmailAddress())) { return true; } $locale = $task->getAssignedTo()->getLocale(); Localization::instance()->loadSettings($locale, ROOT . '/language'); tpl_assign('title', $task->getObjectName()); tpl_assign('by', $task->getAssignedBy()->getObjectName()); tpl_assign('asigned', $task->getAssignedTo()->getObjectName()); $text = ""; if (config_option("wysiwyg_tasks")) { $text = purify_html(nl2br($task->getDescription())); } else { $text = escape_html_whitespace($task->getDescription()); } tpl_assign('description', $text); //descripction tpl_assign('description_title', lang("new task work estimate to you desc", $task->getObjectName(), $task->getCreatedBy()->getObjectName())); //description_title //priority if ($task->getPriority()) { if ($task->getPriority() >= ProjectTasks::PRIORITY_URGENT) { $priorityColor = "#FF0000"; $priority = lang('urgent priority'); } else { if ($task->getPriority() >= ProjectTasks::PRIORITY_HIGH) { $priorityColor = "#FF9088"; $priority = lang('high priority'); } else { if ($task->getPriority() <= ProjectTasks::PRIORITY_LOW) { $priorityColor = "white"; $priority = lang('low priority'); } else { $priorityColor = "#DAE3F0"; $priority = lang('normal priority'); } } } tpl_assign('priority', array($priority, $priorityColor)); } //context $contexts = array(); if ($task->getMembersToDisplayPath()) { $members = $task->getMembersToDisplayPath(); foreach ($members as $key => $member) { $dim = Dimensions::getDimensionById($key); if ($dim->getCode() == "customer_project") { foreach ($members[$key] as $member) { $obj_type = ObjectTypes::findById($member['ot']); $contexts[$dim->getCode()][$obj_type->getName()][] = '<span style="' . get_workspace_css_properties($member['c']) . '">' . $member['name'] . '</span>'; } } else { foreach ($members[$key] as $member) { $contexts[$dim->getCode()][] = '<span style="' . get_workspace_css_properties($member['c']) . '">' . $member['name'] . '</span>'; } } } } tpl_assign('contexts', $contexts); //workspaces //start date, due date or start if ($task->getStartDate() instanceof DateTimeValue) { $date = Localization::instance()->formatDescriptiveDate($task->getStartDate(), $task->getAssignedTo()->getTimezone()); $time = Localization::instance()->formatTime($task->getStartDate(), $task->getAssignedTo()->getTimezone()); if ($time > 0) { $date .= " " . $time; } tpl_assign('start_date', $date); //start_date } if ($task->getDueDate() instanceof DateTimeValue) { $date = Localization::instance()->formatDescriptiveDate($task->getDueDate(), $task->getAssignedTo()->getTimezone()); $time = Localization::instance()->formatTime($task->getDueDate(), $task->getAssignedTo()->getTimezone()); if ($time > 0) { $date .= " " . $time; } tpl_assign('due_date', $date); //due_date } $attachments = array(); try { $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile()); $file_path = ROOT . "/upload/logo_empresa.png"; $handle = fopen($file_path, 'wb'); fwrite($handle, $content); fclose($handle); if ($content != "") { $attachments['logo'] = array('cid' => gen_id() . substr($task->getAssignedBy()->getEmailAddress(), strpos($task->getAssignedBy()->getEmailAddress(), '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png'); tpl_assign('attachments', $attachments); // attachments } } catch (FileNotInRepositoryError $e) { // If no logo is set, don't interrupt notifications. } tpl_assign('attachments', $attachments); // attachments self::queueEmail(array(self::prepareEmailAddress($task->getCreatedBy()->getEmailAddress(), $task->getCreatedBy()->getObjectName())), self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()), lang('work estimate title'), tpl_fetch(get_template_path('work_estimate', 'notifier')), 'text/html', '8bit', $attachments); // send $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION; Localization::instance()->loadSettings($locale, ROOT . '/language'); }
function permission_member_form_parameters($member = null, $dimension_id = null) { if ( $member ) { $dim = $member->getDimension(); }elseif (array_var( $_REQUEST,'dim_id')) { $dim = Dimensions::getDimensionById(array_var( $_REQUEST,'dim_id')); }elseif (!is_null($dimension_id)) { $dim = Dimensions::getDimensionById($dimension_id); } if (!$dim instanceof Dimension) { Logger::log("Invalid dimension: " . ($member instanceof Member ? " for member ".$member->getId() : "request: ".print_r($_REQUEST, 1))); throw new Exception("Invalid dimension"); } if (logged_user()->isMemberOfOwnerCompany()) { $companies = Contacts::findAll(array("conditions" => "is_company = 1 AND object_id IN (SELECT company_id FROM ".TABLE_PREFIX."contacts WHERE user_type>0 AND disabled=0)", 'order' => 'first_name')); } else { $companies = array(owner_company()); if (logged_user()->getCompany() instanceof Contact) $companies[] = logged_user()->getCompany(); } $allowed_object_types = array(); $dim_obj_types = $dim->getAllowedObjectTypeContents(); foreach ($dim_obj_types as $dim_obj_type) { // To draw a row for each object type of the dimension if ( !array_key_exists($dim_obj_type->getContentObjectTypeId(), $allowed_object_types) && (!$member || $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId()) ) { $allowed_object_types[$dim_obj_type->getContentObjectTypeId()] = ObjectTypes::findById($dim_obj_type->getContentObjectTypeId()); $allowed_object_types_json[] = $dim_obj_type->getContentObjectTypeId(); } } $permission_groups = array(); foreach ($companies as $company) { $users = $company->getUsersByCompany(); foreach ($users as $u) $permission_groups[] = $u->getPermissionGroupId(); } $no_company_users = Contacts::getAllUsers("AND `company_id` = 0", true); foreach ($no_company_users as $noc_user) { $permission_groups[] = $noc_user->getPermissionGroupId(); } $non_personal_groups = PermissionGroups::getNonRolePermissionGroups(); foreach ($non_personal_groups as $group) { $permission_groups[] = $group->getId(); } foreach ($permission_groups as $pg_id) { if ($dim->hasAllowAllForContact($pg_id)) { $member_permissions[$pg_id] = array(); foreach ($dim_obj_types as $dim_obj_type) { if ($member && $dim_obj_type->getDimensionObjectTypeId() == $member->getObjectTypeId()) { $member_permissions[$pg_id][] = array( 'o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 1, 'd' => 1, 'r' => 1 ); }elseif(!$member){ // WHEN CREATING a new member dont allow any user $member_permissions[$pg_id][] = array( 'o' => $dim_obj_type->getContentObjectTypeId(), 'w' => 0, 'd' => 0, 'r' => 0 ); } } } else if (!$dim->deniesAllForContact($pg_id)) { $member_permissions[$pg_id] = array(); if ($member) { $mpgs = ContactMemberPermissions::findAll(array("conditions" => array("`permission_group_id` = ? AND `member_id` = ?", $pg_id, $member->getId()))); if (is_array($mpgs)) { foreach ($mpgs as $mpg) { $member_permissions[$mpg->getPermissionGroupId()][] = array( 'o' => $mpg->getObjectTypeId(), 'w' => $mpg->getCanWrite() ? 1 : 0, 'd' => $mpg->getCanDelete() ? 1 : 0, 'r' => 1 ); } } } } } return array( 'member' => $member, 'allowed_object_types' => $allowed_object_types, 'allowed_object_types_json' => $allowed_object_types_json, 'permission_groups' => $permission_groups, 'member_permissions' => $member_permissions, ); }
function view() { $id = array_var($_GET, 'id'); $obj = Objects::findObject($id); if (!$obj) { $obj = Members::getMemberById($id); } if (!$obj instanceof DataObject) { flash_error(lang('object dnx')); ajx_current("empty"); return; } // if if (!$obj->canView(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $object_type = ObjectTypes::findById($obj->getObjectTypeId()); if ($object_type->getType() == 'dimension_object') { ajx_current("empty"); } elseif ($object_type->getType() == 'dimension_group') { ajx_current("empty"); } else { redirect_to($obj->getObjectUrl(), true); } }
if (config_option('getting_started_step') < 99 && !$more_settings_expanded) { // dimension links if (can_manage_dimension_members(logged_user())) { Hook::fire('more_panel_dimension_links', null, $links); $min_steps = count($links); } // add your first object link if (config_option('getting_started_step') < 98) { $object_count_rows = DB::executeAll("SELECT count(o.id) as cant, ot.id as ot_id, ot.name FROM " . TABLE_PREFIX . "objects o INNER JOIN " . TABLE_PREFIX . "object_types ot ON o.object_type_id=ot.id \n\t\t\tWHERE ot.name IN ('task','message','weblink','file','expense','objective','event') AND o.trashed_by_id=0 AND o.archived_by_id=0 GROUP BY ot_id"); $object_count = array(); foreach ($object_count_rows as $row) { $object_count[$row['name']] = $row['cant']; } $first_tab_panel = TabPanels::findOne(array('conditions' => "object_type_id > 0 AND enabled=1 AND id NOT IN ('more-panel', 'reporting-panel', 'mails-panel') AND \n\t\t\t\t(plugin_id is NULL OR plugin_id = 0 OR plugin_id IN (SELECT id FROM " . TABLE_PREFIX . "plugins WHERE is_activated > 0 AND is_installed > 0))", 'order' => 'ordering')); if ($first_tab_panel instanceof TabPanel) { $ot = ObjectTypes::findById($first_tab_panel->getObjectTypeId()); if ($ot instanceof ObjectType) { switch ($ot->getName()) { case "task": $selector = '.task-list-row-template .btn.btn-xs.btn-primary'; break; case "message": case "weblink": case "file": case "expense": case "objective": case "mail": case "contact": case "event": $selector = '#' . $first_tab_panel->getId() . ' .new_button'; break;
function buildMemberList($all_members, $dimension, $allowed_member_type_ids, $allowed_object_type_ids, $item_object, $object_type_id) { $dot_array = array(); // Dimensio Object Types array (cache) $start_time = microtime(1); $membersset = array(); foreach ($all_members as $m) { $membersset[$m->getId()] = true; } $members = array(); foreach ($all_members as $m) { /* @var $m Member */ if ($m->getArchivedById() > 0) { continue; } if ($object_type_id != null) { $selectable = in_array($m->getObjectTypeId(), $allowed_object_type_ids) ? true : false; if ($selectable && isset($item_object)) { if (!$item_object->canAdd(logged_user(), array($m))) { continue; } } } else { $selectable = true; } if (count($allowed_member_type_ids) && !in_array($m->getObjectTypeId(), $allowed_member_type_ids)) { continue; } $tempParent = $m->getParentMemberId(); $x = $m; while ($x instanceof Member && !isset($membersset[$tempParent])) { $tempParent = $x->getParentMemberId(); $x = $x->getParentMember(); } if (!$x instanceof Member) { $tempParent = 0; } $memberOptions = ''; // SET member options (dimension object types table) // CHeck dot cache, if not set goto database and add to cache if (empty($dot_array[$dimension->getId()]) || empty($dot_array[$dimension->getId()][$m->getObjectTypeId()])) { if ($dot = DimensionObjectTypes::instance()->findOne(array("conditions" => "\n\t\t\t\t\tdimension_id = " . $dimension->getId() . " AND\n\t\t\t\t\tobject_type_id = " . $m->getObjectTypeId()))) { if (empty($dot_array['dimension_id'])) { $dot_array[$dimension->getId()] = array(); } $dot_array[$dimension->getId()][$m->getObjectTypeId()] = $dot; } } if (!empty($dot_array[$dimension->getId()]) || $dot_array[$dimension->getId()][$m->getObjectTypeId()] instanceof DimensionObjectType) { $dot = $dot_array[$dimension->getId()][$m->getObjectTypeId()]; $memberOptions = $dot->getOptions(true); } /* @var $m Member */ $member = array("id" => $m->getId(), "name" => clean($m->getName()), "parent" => $tempParent, "realParent" => $m->getParentMemberId(), "object_id" => $m->getObjectId(), "options" => $memberOptions, "depth" => $m->getDepth(), "iconCls" => $m->getIconClass(), "selectable" => isset($selectable) ? $selectable : false, "dimension_id" => $m->getDimensionId(), "object_type_id" => $m->getObjectTypeId(), "allow_childs" => $m->allowChilds()); // Member Actions if (can_manage_dimension_members(logged_user())) { $editUrl = ''; // If member has an object linked, take object edit url if ($otid = $m->getObjectTypeId()) { if ($ot = ObjectTypes::findById($otid)) { if ($handler = $ot->getHandlerClass()) { eval("\$itemClass = {$handler}::instance()->getItemClass();"); if ($itemClass) { $instance = new $itemClass(); $instance->setId($m->getObjectId()); $instance->setObjectId($m->getObjectId()); if ($instance) { $editUrl = $instance->getEditUrl(); } } } } } // Take default membewr edit url if not overwitten if (!$editUrl) { $editUrl = get_url('member', 'edit', array('id' => $m->getId())); } $member['actions'] = array(array('url' => $editUrl, 'text' => '', 'iconCls' => 'ico-edit')); } $members[] = $member; } return $members; }
private function get_report_column_types($report_id) { $col_types = array(); $report = Reports::getReport($report_id); $ot = ObjectTypes::findById($report->getReportObjectTypeId()); $model = $ot->getHandlerClass(); $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 workEstimate(ProjectTask $task) { tpl_assign('task_assigned', $task); if(!($task->getAssignedTo() instanceof Contact)) { return true; // not assigned to user } if (!is_valid_email($task->getAssignedTo()->getEmailAddress())) { return true; } $locale = $task->getAssignedTo()->getLocale(); Localization::instance()->loadSettings($locale, ROOT . '/language'); tpl_assign('title', $task->getObjectName()); tpl_assign('by', $task->getAssignedBy()->getObjectName()); tpl_assign('asigned', $task->getAssignedTo()->getObjectName()); $text = ""; if(config_option("wysiwyg_tasks")){ $text = purify_html(nl2br($task->getDescription())); }else{ $text = escape_html_whitespace($task->getDescription()); } tpl_assign('description', $text);//descripction tpl_assign('description_title', lang("new task work estimate to you desc", $task->getObjectName(),$task->getAssignedBy()->getObjectName()));//description_title //priority if ($task->getPriority()) { if ($task->getPriority() >= ProjectTasks::PRIORITY_URGENT) { $priorityColor = "#FF0000"; $priority = lang('urgent priority'); }else if ($task->getPriority() >= ProjectTasks::PRIORITY_HIGH) { $priorityColor = "#FF9088"; $priority = lang('high priority'); } else if ($task->getPriority() <= ProjectTasks::PRIORITY_LOW) { $priorityColor = "white"; $priority = lang('low priority'); }else{ $priorityColor = "#DAE3F0"; $priority = lang('normal priority'); } tpl_assign('priority', array($priority,$priorityColor)); } //context $contexts = array(); $members = $task->getMembers(); if(count($members)>0){ foreach ($members as $member){ $dim = $member->getDimension(); if($dim->getIsManageable()){ if ($dim->getCode() == "customer_project"){ $obj_type = ObjectTypes::findById($member->getObjectTypeId()); if ($obj_type instanceof ObjectType) { $contexts[$dim->getCode()][$obj_type->getName()][]= '<span style="'.get_workspace_css_properties($member->getMemberColor()).'">'. $member->getName() .'</span>'; } }else{ $contexts[$dim->getCode()][]= '<span style="'.get_workspace_css_properties($member->getMemberColor()).'">'. $member->getName() .'</span>'; } } } } tpl_assign('contexts', $contexts);//workspaces //start date, due date or start if ($task->getStartDate() instanceof DateTimeValue) { $date = Localization::instance()->formatDescriptiveDate($task->getStartDate(), $task->getAssignedTo()->getTimezone()); $time = Localization::instance()->formatTime($task->getStartDate(), $task->getAssignedTo()->getTimezone()); if($time > 0) $date .= " " . $time; tpl_assign('start_date', $date);//start_date } if ($task->getDueDate() instanceof DateTimeValue) { $date = Localization::instance()->formatDescriptiveDate($task->getDueDate(), $task->getAssignedTo()->getTimezone()); $time = Localization::instance()->formatTime($task->getDueDate(), $task->getAssignedTo()->getTimezone()); if($time > 0) $date .= " " . $time; tpl_assign('due_date', $date);//due_date } $attachments = array(); try { $content = FileRepository::getBackend()->getFileContent(owner_company()->getPictureFile()); if ($content) { $file_path = ROOT . "/tmp/logo_empresa.png"; $handle = fopen($file_path, 'wb'); if ($handle) { fwrite($handle, $content); fclose($handle); $attachments['logo'] = array( 'cid' => gen_id() . substr($task->getAssignedBy()->getEmailAddress(), strpos($task->getAssignedBy()->getEmailAddress(), '@')), 'path' => $file_path, 'type' => 'image/png', 'disposition' => 'inline', 'name' => 'logo_empresa.png', ); } } } catch (FileNotInRepositoryError $e) { unset($attachments['logo']); } tpl_assign('attachments', $attachments);// attachments //ALL SUBSCRIBERS if($task->getSubscribers()){ $subscribers = $task->getSubscribers(); $string_subscriber = ''; $total_s = count($subscribers); $c = 0; foreach ($subscribers as $subscriber){ $c++; if($c == $total_s && $total_s > 1){ $string_subscriber .= lang('and'); }else if($c > 1){ $string_subscriber .= ", "; } $string_subscriber .= $subscriber->getFirstName(); if($subscriber->getSurname() != "") $string_subscriber .=" " . $subscriber->getSurname(); } tpl_assign('subscribers', $string_subscriber);// subscribers } if($task->getAssignedById() == $task->getAssignedToContactId()){ $emails[] = array( "to" => array(self::prepareEmailAddress($task->getAssignedBy()->getEmailAddress(), $task->getAssignedBy()->getObjectName())), "from" => self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()), "subject" => lang('work estimate title'), "body" => tpl_fetch(get_template_path('work_estimate', 'notifier')), "attachments" => $attachments ); }else{ $emails[] = array( "to" => array(self::prepareEmailAddress($task->getAssignedBy()->getEmailAddress(), $task->getAssignedBy()->getObjectName())), "from" => self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()), "subject" => lang('work estimate title'), "body" => tpl_fetch(get_template_path('work_estimate', 'notifier')), "attachments" => $attachments ); $emails[] = array( "to" => array(self::prepareEmailAddress($task->getAssignedTo()->getEmailAddress(), $task->getAssignedTo()->getObjectName())), "from" => self::prepareEmailAddress($task->getUpdatedBy()->getEmailAddress(), $task->getUpdatedByDisplayName()), "subject" => lang('work estimate title'), "body" => tpl_fetch(get_template_path('work_estimate', 'notifier')), "attachments" => $attachments ); } self::queueEmails($emails); $locale = logged_user() instanceof Contact ? logged_user()->getLocale() : DEFAULT_LOCALIZATION; Localization::instance()->loadSettings($locale, ROOT . '/language'); }
/** * @author Ignacio Vazquez <elpepe.uy at gmail dot com> * Handle quick add submit */ function quick_add() { if (array_var($_GET, 'current') == 'overview-panel') { ajx_current("reload"); } else { ajx_current("empty"); } //---------- REQUEST PARAMS -------------- // $_POST = Array ( // [member] => Array ( // [name] => pepe 333 // [dimension_id] => 1 // [parent_member_id] => 0 // [dimension_id] => 19 // ) // [contact] => Array ( // [email] => slkdjflksjdflksdf@kldsjflkdf.com // [user] => Array ( // [create-user]=>on // [type] => 25 // [first_name] => // [surname] => // ) //---------------------------------------- //alert_r($_POST['contact']); // Init variables $max_users = config_option('max_users'); if ($max_users && Contacts::count() >= $max_users) { flash_error(lang('maximum number of users reached error')); ajx_current("empty"); return; } if (!can_manage_security(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $email = trim(array_var(array_var($_POST, 'contact'), 'email')); $member = array_var($_POST, 'member'); $name = array_var($member, 'name'); $firstName = trim(array_var(array_var($_POST, 'contact'), 'first_name')); $surname = trim(array_var(array_var($_POST, 'contact'), 'surname')); $parentMemberId = array_var($member, 'parent_member_id'); $objectType = ObjectTypes::findById(array_var($member, 'object_type_id'))->getName(); // 'person', 'company' $dimensionId = array_var($member, 'dimension_id'); $company = array_var(array_var(array_var($_POST, 'contact'), 'user'), 'company_id'); // Create new instance of Contact and set the basic fields $contact = new Contact(); $contact->setObjectName($name); if ($firstName) { $contact->setFirstName($firstName); } else { $contact->setFirstName($name); } if ($surname) { $contact->setSurname($surname); } $contact->setCompanyId($company); $contact->setIsCompany($objectType == "company"); if ($parentMemberId) { if ($companyId = Members::findById($parentMemberId)->getObjectId()) { $contact->setCompanyId($companyId); } } // Save Contact try { DB::beginWork(); $contact->save(); if ($email && is_valid_email($email)) { if (!Contacts::validateUniqueEmail($email)) { DB::rollback(); flash_error(lang("email address must be unique")); return false; } else { if (!array_var(array_var(array_var($_POST, 'contact'), 'user'), 'create-user')) { $contact->addEmail($email, 'personal', true); } flash_success(lang("success add contact", $contact->getObjectName())); } } // User settings $user = array_var(array_var($_POST, 'contact'), 'user'); $user['username'] = str_replace(" ", "", strtolower($name)); $this->createUserFromContactForm($user, $contact->getId(), $email); // Reload contact again due to 'createUserFromContactForm' changes Hook::fire("after_contact_quick_add", Contacts::instance()->findById($contact->getId()), $ret); DB::commit(); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } // Reload evt_add("reload dimension tree", $dimensionId); }
function getObjectHandlerClass() { if ($otid = $this->getObjectTypeId()) { if ($ot = ObjectTypes::findById($otid)) { if ($handler = $ot->getHandlerClass()) { return $handler; } } } return ''; }
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; }
private static function buildContextObjectForNotification($object) { $contexts = array(); $members = $object->getMembers(); if (count($members) > 0) { foreach ($members as $member) { $dim = $member->getDimension(); if ($dim->getIsManageable()) { /* @var $member Member */ $parent_members = $member->getAllParentMembersInHierarchy(); $parents_str = ''; foreach ($parent_members as $pm) { /* @var $pm Member */ if (!$pm instanceof Member) { continue; } $parents_str .= '<span style="' . get_workspace_css_properties($pm->getMemberColor()) . '">' . $pm->getName() . '</span>'; } if ($dim->getCode() == "customer_project" || $dim->getCode() == "customers") { $obj_type = ObjectTypes::findById($member->getObjectTypeId()); if ($obj_type instanceof ObjectType) { $contexts[$dim->getCode()][$obj_type->getName()][] = $parents_str . '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>'; } } else { $contexts[$dim->getCode()][] = $parents_str . '<span style="' . get_workspace_css_properties($member->getMemberColor()) . '">' . $member->getName() . '</span>'; } } } } return $contexts; }
/** * Execute a report and return results * * @param $id * @param $params * * @return array */ static function executeReport($id, $params, $order_by_col = '', $order_by_asc = true, $offset=0, $limit=50, $to_print = false) { if (is_null(active_context())) { CompanyWebsite::instance()->setContext(build_context_array(array_var($_REQUEST, 'context'))); } $results = array(); $report = self::getReport($id); if($report instanceof Report){ $conditionsFields = ReportConditions::getAllReportConditionsForFields($id); $conditionsCp = ReportConditions::getAllReportConditionsForCustomProperties($id); $ot = ObjectTypes::findById($report->getReportObjectTypeId()); $table = $ot->getTableName(); eval('$managerInstance = ' . $ot->getHandlerClass() . "::instance();"); eval('$item_class = ' . $ot->getHandlerClass() . '::instance()->getItemClass(); $object = new $item_class();'); $order_by = ''; if (is_object($params)) { $params = get_object_vars($params); } $report_columns = ReportColumns::getAllReportColumns($id); $allConditions = ""; if(count($conditionsFields) > 0){ foreach($conditionsFields as $condField){ $skip_condition = false; $model = $ot->getHandlerClass(); $model_instance = new $model(); $col_type = $model_instance->getColumnType($condField->getFieldName()); $allConditions .= ' AND '; $dateFormat = 'm/d/Y'; if(isset($params[$condField->getId()])){ $value = $params[$condField->getId()]; if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) $dateFormat = user_config_option('date_format'); } else { $value = $condField->getValue(); } if ($value == '' && $condField->getIsParametrizable()) $skip_condition = true; if (!$skip_condition) { if($condField->getCondition() == 'like' || $condField->getCondition() == 'not like'){ $value = '%'.$value.'%'; } if ($col_type == DATA_TYPE_DATE || $col_type == DATA_TYPE_DATETIME) { $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value); $value = $dtValue->format('Y-m-d'); } if($condField->getCondition() != '%'){ if ($col_type == DATA_TYPE_INTEGER || $col_type == DATA_TYPE_FLOAT) { $allConditions .= '`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value); } else { if ($condField->getCondition()=='=' || $condField->getCondition()=='<=' || $condField->getCondition()=='>='){ if ($col_type == DATA_TYPE_DATETIME || $col_type == DATA_TYPE_DATE) { $equal = 'datediff('.DB::escape($value).', `'.$condField->getFieldName().'`)=0'; } else { $equal = '`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value); } switch($condField->getCondition()){ case '=': $allConditions .= $equal; break; case '<=': case '>=': $allConditions .= '(`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value).' OR '.$equal.') '; break; } } else { $allConditions .= '`'.$condField->getFieldName().'` '.$condField->getCondition().' '.DB::escape($value); } } } else { $allConditions .= '`'.$condField->getFieldName().'` like '.DB::escape("%$value"); } } else $allConditions .= ' true'; } } if(count($conditionsCp) > 0){ $dateFormat = user_config_option('date_format'); $date_format_tip = date_format_tip($dateFormat); foreach($conditionsCp as $condCp){ $cp = CustomProperties::getCustomProperty($condCp->getCustomPropertyId()); $skip_condition = false; if(isset($params[$condCp->getId()."_".$cp->getName()])){ $value = $params[$condCp->getId()."_".$cp->getName()]; }else{ $value = $condCp->getValue(); } if ($value == '' && $condCp->getIsParametrizable()) $skip_condition = true; if (!$skip_condition) { $current_condition = ' AND '; $current_condition .= 'o.id IN ( SELECT object_id as id FROM '.TABLE_PREFIX.'custom_property_values cpv WHERE '; $current_condition .= ' cpv.custom_property_id = '.$condCp->getCustomPropertyId(); $fieldType = $object->getColumnType($condCp->getFieldName()); if($condCp->getCondition() == 'like' || $condCp->getCondition() == 'not like'){ $value = '%'.$value.'%'; } if ($cp->getType() == 'date') { if ($value == $date_format_tip) continue; $dtValue = DateTimeValueLib::dateFromFormatAndString($dateFormat, $value); $value = $dtValue->format('Y-m-d H:i:s'); } if($condCp->getCondition() != '%'){ if ($cp->getType() == 'numeric') { $current_condition .= ' AND cpv.value '.$condCp->getCondition().' '.DB::escape($value); }else if ($cp->getType() == 'boolean') { $current_condition .= ' AND cpv.value '.$condCp->getCondition().' '.$value; if (!$value) { $current_condition .= ') OR o.id NOT IN (SELECT object_id as id FROM '.TABLE_PREFIX.'custom_property_values cpv2 WHERE cpv2.object_id=o.id AND cpv2.value=1 AND cpv2.custom_property_id = '.$condCp->getCustomPropertyId(); } }else{ $current_condition .= ' AND cpv.value '.$condCp->getCondition().' '.DB::escape($value); } }else{ $current_condition .= ' AND cpv.value like '.DB::escape("%$value"); } $current_condition .= ')'; $allConditions .= $current_condition; } } } $select_columns = array('*'); $join_params = null; if ($order_by_col == '') { $order_by_col = $report->getOrderBy(); } if (in_array($order_by_col, self::$external_columns)) { $original_order_by_col = $order_by_col; $order_by_col = 'name_order'; $join_params = array( 'table' => Objects::instance()->getTableName(), 'jt_field' => 'id', 'e_field' => $original_order_by_col, 'join_type' => 'left' ); $select_columns = array(); $tmp_cols = $managerInstance->getColumns(); foreach ($tmp_cols as $col) $select_columns[] = "e.$col"; $tmp_cols = Objects::instance()->getColumns(); foreach ($tmp_cols as $col) $select_columns[] = "o.$col"; $select_columns[] = 'jt.name as name_order'; } if ($order_by_asc == null) $order_by_asc = $report->getIsOrderByAsc(); if ($ot->getName() == 'task' && !SystemPermissions::userHasSystemPermission(logged_user(), 'can_see_assigned_to_other_tasks')) { $allConditions .= " AND assigned_to_contact_id = ".logged_user()->getId(); } if ($managerInstance) { $result = $managerInstance->listing(array( "select_columns" => $select_columns, "order" => "$order_by_col", "order_dir" => ($order_by_asc ? "ASC" : "DESC"), "extra_conditions" => $allConditions, "join_params" => $join_params )); }else{ // TODO Performance Killer $result = ContentDataObjects::getContentObjects(active_context(), $ot, $order_by_col, ($order_by_asc ? "ASC" : "DESC"), $allConditions); } $objects = $result->objects; $totalResults = $result->total; $results['pagination'] = Reports::getReportPagination($id, $params, $order_by_col, $order_by_asc, $offset, $limit, $totalResults); $dimensions_cache = array(); foreach($report_columns as $column){ if ($column->getCustomPropertyId() == 0) { $field = $column->getFieldName(); if (str_starts_with($field, 'dim_')) { $dim_id = str_replace("dim_", "", $field); $dimension = Dimensions::getDimensionById($dim_id); $dimensions_cache[$dim_id] = $dimension; $doptions = $dimension->getOptions(true); $column_name = $doptions && isset($doptions->useLangs) && $doptions->useLangs ? lang($dimension->getCode()) : $dimension->getName(); $results['columns'][$field] = $column_name; $results['db_columns'][$column_name] = $field; } else { if ($managerInstance->columnExists($field) || Objects::instance()->columnExists($field)) { $column_name = Localization::instance()->lang('field '.$ot->getHandlerClass().' '.$field); if (is_null($column_name)) $column_name = lang('field Objects '.$field); $results['columns'][$field] = $column_name; $results['db_columns'][$column_name] = $field; } } } else { $results['columns'][$column->getCustomPropertyId()] = $column->getCustomPropertyId(); } } $report_rows = array(); foreach($objects as &$object){/* @var $object Object */ $obj_name = $object->getObjectName(); $icon_class = $object->getIconClass(); $row_values = array('object_type_id' => $object->getObjectTypeId()); if (!$to_print) { $row_values['link'] = '<a class="link-ico '.$icon_class.'" title="' . $obj_name . '" target="new" href="' . $object->getViewUrl() . '"> </a>'; } foreach($report_columns as $column){ if ($column->getCustomPropertyId() == 0) { $field = $column->getFieldName(); if (str_starts_with($field, 'dim_')) { $dim_id = str_replace("dim_", "", $field); if (!array_var($dimensions_cache, $dim_id) instanceof Dimension) { $dimension = Dimensions::getDimensionById($dim_id); $dimensions_cache[$dim_id] = $dimension; } else { $dimension = array_var($dimensions_cache, $dim_id); } $members = ObjectMembers::getMembersByObjectAndDimension($object->getId(), $dim_id, " AND om.is_optimization=0"); $value = ""; foreach ($members as $member) {/* @var $member Member */ $val = $member->getPath(); $val .= ($val == "" ? "" : "/") . $member->getName(); if ($value != "") $val = " - $val"; $value .= $val; } $row_values[$field] = $value; } else { $value = $object->getColumnValue($field); if ($value instanceof DateTimeValue) { $field_type = $managerInstance->columnExists($field) ? $managerInstance->getColumnType($field) : Objects::instance()->getColumnType($field); $value = format_value_to_print($field, $value->toMySQL(), $field_type, $report->getReportObjectTypeId()); } if(in_array($field, $managerInstance->getExternalColumns())){ $value = self::instance()->getExternalColumnValue($field, $value, $managerInstance); } else if ($field != 'link'){ $value = html_to_text($value); } if(self::isReportColumnEmail($value)) { if(logged_user()->hasMailAccounts()){ $value = '<a class="internalLink" href="'.get_url('mail', 'add_mail', array('to' => clean($value))).'">'.clean($value).'</a></div>'; }else{ $value = '<a class="internalLink" target="_self" href="mailto:'.clean($value).'">'.clean($value).'</a></div>'; } } $row_values[$field] = $value; } } else { $colCp = $column->getCustomPropertyId(); $cp = CustomProperties::getCustomProperty($colCp); if ($cp instanceof CustomProperty) { /* @var $cp CustomProperty */ $cp_val = CustomPropertyValues::getCustomPropertyValue($object->getId(), $colCp); $row_values[$cp->getName()] = $cp_val instanceof CustomPropertyValue ? $cp_val->getValue() : ""; $results['columns'][$colCp] = $cp->getName(); $results['db_columns'][$cp->getName()] = $colCp; } } } Hook::fire("report_row", $object, $row_values); $report_rows[] = $row_values; } if (!$to_print) { if (is_array($results['columns'])) { array_unshift($results['columns'], ''); } else { $results['columns'] = array(''); } Hook::fire("report_header", $ot, $results['columns']); } $results['rows'] = $report_rows; } return $results; } // executeReport
function buildMemberList($all_members, $dimension, $allowed_member_type_ids, $allowed_object_type_ids, $item_object, $object_type_id, $return_only_name = false) { $dot_array = array(); // Dimension Object Types array (cache) $membersset = array(); foreach ($all_members as $m) { $membersset[$m->getId()] = true; } $members = array(); foreach ($all_members as $m) { /* @var $m Member */ // if ($m->getArchivedById() > 0) continue; if ($object_type_id != null) { $selectable = in_array($m->getObjectTypeId(), $allowed_object_type_ids) ? true : false; if ($selectable && isset($item_object)) { if (!$item_object->canAdd(logged_user(), array($m))) { continue; } } } else { $selectable = true; } if (count($allowed_member_type_ids) && !in_array($m->getObjectTypeId(), $allowed_member_type_ids)) { continue; } $tempParent = $m->getParentMemberId(); //check if have parent member id from Contact Member Cache if (isset($m->cached_parent_member_id)) { $tempParent = $m->cached_parent_member_id; } else { if (!logged_user()->isAdministrator()) { $x = $m; while ($x instanceof Member && !isset($membersset[$tempParent])) { $tempParent = $x->getParentMemberId(); if ($x->getParentMemberId() == 0) { break; } $x = $x->getParentMember(); } if (!$x instanceof Member) { $tempParent = 0; } } else { $tempParent = $m->getParentMemberId(); } } $memberOptions = ''; // SET member options (dimension object types table) // CHeck dot cache, if not set goto database and add to cache if (empty($dot_array[$dimension->getId()]) || empty($dot_array[$dimension->getId()][$m->getObjectTypeId()])) { $dot = DimensionObjectTypes::instance()->findOne(array("conditions" => "dimension_id = " . $dimension->getId() . " AND object_type_id = " . $m->getObjectTypeId())); if ($dot instanceof DimensionObjectType) { if (empty($dot_array['dimension_id'])) { $dot_array[$dimension->getId()] = array(); } $dot_array[$dimension->getId()][$m->getObjectTypeId()] = $dot; } } if (!empty($dot_array[$dimension->getId()]) || $dot_array[$dimension->getId()][$m->getObjectTypeId()] instanceof DimensionObjectType) { $dot = $dot_array[$dimension->getId()][$m->getObjectTypeId()]; if ($dot) { $memberOptions = $dot->getOptions(true); } } if ($return_only_name) { $path = trim($m->getPath()); $member = array("id" => $m->getId(), "name" => $m->getName(), "path" => $path, "depth" => $m->getDepth(), "to_show" => $m->getName() . ($path != "" ? " ({$path})" : ""), "dim" => $m->getDimensionId(), "ico" => "ico-color" . $m->getColor() . " " . $m->getIconClass()); } else { //Do not use contact member cache for superadmins if (!logged_user()->isAdministrator()) { //check childs from contact member cache $childsIds = ContactMemberCaches::getAllChildrenIdsFromCache(logged_user()->getId(), $m->getId()); } else { $childsIds = $m->getAllChildrenIds(false, null, ""); } $totalChilds = count($childsIds); $haveChilds = $totalChilds > 0 ? true : false; /* @var $m Member */ $additional_member_class = ""; Hook::fire('additional_member_node_class', $m, $additional_member_class); $member = array("id" => $m->getId(), "color" => $m->getMemberColor(), "name" => clean($m->getName()), "text" => clean($m->getName()), "leaf" => true, "parent" => $tempParent, "realParent" => $m->getParentMemberId(), "object_id" => $m->getObjectId(), "options" => $memberOptions, "depth" => $m->getDepth(), "cls" => $additional_member_class, "iconCls" => "ico-color" . $m->getColor() . " " . $m->getIconClass(), "selectable" => isset($selectable) ? $selectable : false, "dimension_id" => $m->getDimensionId(), "object_type_id" => $m->getObjectTypeId(), "expandable" => $haveChilds, "realTotalChilds" => $totalChilds, "allow_childs" => $m->allowChilds()); // Member Actions if (can_manage_dimension_members(logged_user())) { $editUrl = ''; // If member has an object linked, take object edit url if ($ot = ObjectTypes::findById($m->getObjectTypeId())) { if ($handler = $ot->getHandlerClass()) { eval("\$itemClass = {$handler}::instance()->getItemClass();"); if ($itemClass) { $instance = new $itemClass(); $instance->setId($m->getObjectId()); $instance->setObjectId($m->getObjectId()); if ($instance instanceof Contact) { if ($ot->getName() == 'company') { $instance->setIsCompany(1); } } $editUrl = $instance->getEditUrl(); } } } // Take default membewr edit url if not overwitten if (!$editUrl) { $editUrl = get_url('member', 'edit', array('id' => $m->getId())); } $member['actions'] = array(array('url' => $editUrl, 'text' => '', 'iconCls' => 'ico-edit', 'class' => 'action-edit')); } } $members[] = $member; } // re-sort by parent and name $tmp_members = array(); foreach ($members as $m) { $tmp_members[str_pad(array_var($m, 'depth'), 20, "0", STR_PAD_LEFT) . strtolower(array_var($m, 'name')) . array_var($m, 'id')] = $m; } ksort($tmp_members, SORT_STRING); $members = $tmp_members; return $members; }
/** * @author Ignacio Vazquez elpepe.uy at gmail.com * Fermormance FIX: getContentObjects replacement * @param array $args * order = null - may be performance killer depending on the order criteria * order_dir = null * extra_conditions = null : extra sql 'inyection' - may be performance killer depending on the injected query * join_params = null : extra join table * trashed = false * archived = false * start = 0 * limit = null * ignore_context * include_deleted * count_results : if true calc found rows else show 'many' * extra_member_ids : Search also objects in this slist of members * member_ids : force to search objects in this list of members (strinct) * */ public function listing($args = array()) { if ( defined('DEBUG_TIME') && DEBUG_TIME ) { $start_time = microtime(1); } $result = new stdClass ; $result->objects =array(); $result->total =array(); $type_id = self::getObjectTypeId(); $SQL_BASE_JOIN = ''; $SQL_EXTRA_JOINS = ''; $SQL_TYPE_CONDITION = 'true'; if (isset($args['count_results'])) { $count_results = $args['count_results']; } else { $count_results = !( defined('INFINITE_PAGING') && INFINITE_PAGING ); } $return_raw_data = array_var($args,'raw_data'); $start = array_var($args,'start'); $limit = array_var($args,'limit'); $member_ids = array_var($args, 'member_ids'); $extra_member_ids = array_var($args,'extra_member_ids'); $ignore_context = array_var($args,'ignore_context'); $include_deleted = (bool) array_var($args,'include_deleted'); $select_columns = array_var($args, 'select_columns', array('*')); if ($count_results) { $SQL_FOUND_ROWS = "SQL_CALC_FOUND_ROWS"; }else{ $SQL_FOUND_ROWS = ""; } $handler_class = "Objects"; if ($type_id){ // If isset type, is a concrete instance linsting. Otherwise is a generic listing of objects $type = ObjectTypes::findById($type_id); /* @var $object_type ObjectType */ $handler_class = $type->getHandlerClass(); $table_name = self::getTableName(); // Extra Join statements if ($this instanceof ContentDataObjects && $this->object_type_name == 'timeslot') { // if object is a timeslot and is related to a content object => check for members of the related content object. $SQL_BASE_JOIN = " INNER JOIN $table_name e ON IF(e.rel_object_id > 0, e.rel_object_id, e.object_id) = o.id "; $SQL_TYPE_CONDITION = "object_type_id = IF(e.rel_object_id > 0, (SELECT z.object_type_id FROM ".TABLE_PREFIX."objects z WHERE z.id = e.rel_object_id), $type_id)"; } else { $SQL_BASE_JOIN = " INNER JOIN $table_name e ON e.object_id = o.id "; $SQL_TYPE_CONDITION = "o.object_type_id = $type_id"; } $SQL_EXTRA_JOINS = self::prepareJoinConditions(array_var($args,'join_params')); } if (!$ignore_context && !$member_ids) { $members = active_context_members(false); // Context Members Ids } elseif ( count($member_ids) ) { $members = $member_ids; } if (is_array($extra_member_ids)) { if (isset($members)) { $members = array_merge($members, $extra_member_ids); } else { $members = $extra_member_ids; } } $uid = logged_user()->getId() ; // Order statement $SQL_ORDER = self::prepareOrderConditions(array_var($args,'order'), array_var($args,'order_dir')); // Prepare Limit SQL if (is_numeric(array_var($args,'limit')) && is_numeric(array_var($args,'start')) && array_var($args,'limit')>0){ $SQL_LIMIT = "LIMIT ".array_var($args,'start',0)." , ".array_var($args,'limit'); }else{ $SQL_LIMIT = '' ; } $SQL_CONTEXT_CONDITION = " true "; if (!empty($members) && count($members)) { $object_ids = array (); $members_sql = " SELECT object_id FROM " . TABLE_PREFIX . "object_members om WHERE member_id IN (" . implode ( ',', $members ) . ") GROUP BY object_id HAVING count(member_id) = ".count($members); $db_result = DB::execute ( $members_sql ); $rows = $db_result->fetchAll(); if (is_array($rows)){ foreach ( $rows as $row ) { $object_ids [$row ['object_id']] = $row ['object_id']; } } if (count( $object_ids )) { $object_ids = implode ( ",", $object_ids ); $SQL_CONTEXT_CONDITION = "o.id IN ($object_ids)"; }else{ $SQL_CONTEXT_CONDITION = ' false ' ; } } // Trash && Archived CONDITIONS $trashed_archived_conditions = self::prepareTrashandArchivedConditions(array_var($args,'trashed'), array_var($args,'archived')); $SQL_TRASHED_CONDITION = ($include_deleted) ? ' TRUE ' : $trashed_archived_conditions[0]; $SQL_ARCHIVED_CONDITION =($include_deleted) ? ' AND TRUE ' : $trashed_archived_conditions[1]; // Extra CONDITIONS if (array_var($args,'extra_conditions')) { $SQL_EXTRA_CONDITIONS = array_var($args,'extra_conditions') ; }else{ $SQL_EXTRA_CONDITIONS = ''; } $SQL_COLUMNS = implode(',', $select_columns); // Build Main SQL $sql = " SELECT $SQL_FOUND_ROWS $SQL_COLUMNS FROM ".TABLE_PREFIX."objects o $SQL_BASE_JOIN $SQL_EXTRA_JOINS WHERE o.id IN ( SELECT object_id FROM ".TABLE_PREFIX."sharing_table WHERE group_id IN ( SELECT permission_group_id FROM ".TABLE_PREFIX."contact_permission_groups WHERE contact_id = $uid ) ) AND $SQL_CONTEXT_CONDITION AND $SQL_TYPE_CONDITION AND $SQL_TRASHED_CONDITION $SQL_ARCHIVED_CONDITION $SQL_EXTRA_CONDITIONS $SQL_ORDER $SQL_LIMIT"; // Execute query and build the resultset $rows = DB::executeAll($sql); if ($return_raw_data) { $result->objects = $rows; } else { if($rows && is_array($rows)) { foreach ($rows as $row) { if ($handler_class) { $phpCode = '$co = '.$handler_class.'::instance()->loadFromRow($row);'; eval($phpCode); } if ( $co ) { $result->objects[] = $co ; } } } } if ($count_results) { $total = DB::executeOne("SELECT FOUND_ROWS() as total"); $result->total = $total['total']; }else{ if ( count($result->objects) == $limit ) { $result->total = 10000000; }else{ $result->total = $start + count($result->objects) ; } } if ( defined('DEBUG_TIME') && DEBUG_TIME ) { Logger::log("Query time: ". (microtime(1) - $start_time) ) ; } return $result; }
/** * Fermormance FIX: getContentObjects replacement * @param array $args * order = null - may be performance killer depending on the order criteria * order_dir = null * extra_conditions = null : extra sql 'inyection' - may be performance killer depending on the injected query * join_params = null : extra join table * trashed = false * archived = false * start = 0 * limit = null * ignore_context * include_deleted * count_results : if true calc found rows else show 'many' * extra_member_ids : Search also objects in this slist of members * member_ids : force to search objects in this list of members (strinct) * */ public function listing($args = array()) { $result = new stdClass(); $result->objects = array(); $result->total = array(); $type_id = self::getObjectTypeId(); $SQL_BASE_JOIN = ''; $SQL_EXTRA_JOINS = ''; $SQL_TYPE_CONDITION = 'true'; $SQL_FOUND_ROWS = ''; if (isset($args['count_results'])) { $count_results = $args['count_results']; } else { $count_results = defined('INFINITE_PAGING') ? !INFINITE_PAGING : false; } //get only the number of results without limit not data if (isset($args['only_count_results'])) { $only_count_results = $args['only_count_results']; } else { $only_count_results = false; } $return_raw_data = array_var($args, 'raw_data'); $start = array_var($args, 'start'); $limit = array_var($args, 'limit'); $member_ids = array_var($args, 'member_ids'); $extra_member_ids = array_var($args, 'extra_member_ids'); $ignore_context = array_var($args, 'ignore_context'); $include_deleted = (bool) array_var($args, 'include_deleted'); $select_columns = array_var($args, 'select_columns'); if (empty($select_columns)) { $select_columns = array('*'); } //template objects $template_objects = (bool) array_var($args, 'template_objects', false); $handler_class = "Objects"; if ($type_id) { // If isset type, is a concrete instance linsting. Otherwise is a generic listing of objects $type = ObjectTypes::findById($type_id); /* @var $object_type ObjectType */ $handler_class = $type->getHandlerClass(); $table_name = self::getTableName(); // Extra Join statements if ($this instanceof ContentDataObjects && $this->object_type_name == 'timeslot') { // if object is a timeslot and is related to a content object => check for members of the related content object. $SQL_BASE_JOIN = " INNER JOIN {$table_name} e ON IF(e.rel_object_id > 0, e.rel_object_id, e.object_id) = o.id "; $SQL_TYPE_CONDITION = "o.object_type_id = IF(e.rel_object_id > 0, (SELECT z.object_type_id FROM " . TABLE_PREFIX . "objects z WHERE z.id = e.rel_object_id), {$type_id})"; } else { $SQL_BASE_JOIN = " INNER JOIN {$table_name} e ON e.object_id = o.id "; $SQL_TYPE_CONDITION = "o.object_type_id = {$type_id}"; } $SQL_EXTRA_JOINS = self::prepareJoinConditions(array_var($args, 'join_params')); } if (!$ignore_context && !$member_ids) { $members = active_context_members(false); // Context Members Ids } elseif (count($member_ids)) { $members = $member_ids; } if (is_array($extra_member_ids)) { if (isset($members)) { $members = array_merge($members, $extra_member_ids); } else { $members = $extra_member_ids; } } // Order statement $SQL_ORDER = self::prepareOrderConditions(array_var($args, 'order'), array_var($args, 'order_dir')); // Prepare Limit SQL if (is_numeric(array_var($args, 'limit')) && array_var($args, 'limit') > 0) { $SQL_LIMIT = "LIMIT " . array_var($args, 'start', 0) . " , " . array_var($args, 'limit'); } else { $SQL_LIMIT = ''; } // Prepare Group By SQL $group_by = array_var($args,'group_by'); if (array_var($args, 'group_by')) { $SQL_GROUP_BY = "GROUP BY " . array_var($args, 'group_by'); } else { $SQL_GROUP_BY = ''; } $SQL_CONTEXT_CONDITION = " true "; //show only objects that are on this members by classification not by hierarchy $show_only_member_objects = array_var($args, 'show_only_member_objects', false); $exclusive_in_member = ''; if ($show_only_member_objects) { $exclusive_in_member = " AND om.`is_optimization` = 0"; } if (!empty($members) && count($members)) { $SQL_CONTEXT_CONDITION = "(EXISTS (SELECT om.object_id\r\n\t\t\t\t\tFROM " . TABLE_PREFIX . "object_members om\r\n\t\t\t\t\tWHERE\tom.member_id IN (" . implode(',', $members) . ") AND o.id = om.object_id {$exclusive_in_member}\r\n\t\t\t\t\tGROUP BY object_id\r\n\t\t\t\t\tHAVING count(member_id) = " . count($members) . "\r\n\t\t\t))"; } else { //show only objects that are on root if ($show_only_member_objects) { if (is_array(active_context())) { $active_dims_ids = array(); foreach (active_context() as $ctx) { if ($ctx instanceof Dimension) { $active_dims_ids[] = $ctx->getId(); } } if (count($active_dims_ids) > 0) { $SQL_CONTEXT_CONDITION = "(NOT EXISTS (SELECT om.object_id\r\n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "object_members om\r\n\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "members mem ON mem.id = om.member_id AND mem.dimension_id IN (" . implode(",", $active_dims_ids) . ")\r\n\t\t\t\t\t\t\tWHERE\to.id = om.object_id\r\n\t\t\t\t\t\t\t))"; } } } } // Trash && Archived CONDITIONS $trashed_archived_conditions = self::prepareTrashandArchivedConditions(array_var($args, 'trashed'), array_var($args, 'archived')); $SQL_TRASHED_CONDITION = $include_deleted ? ' TRUE ' : $trashed_archived_conditions[0]; $SQL_ARCHIVED_CONDITION = $include_deleted ? ' AND TRUE ' : $trashed_archived_conditions[1]; // Extra CONDITIONS if (array_var($args, 'extra_conditions')) { $SQL_EXTRA_CONDITIONS = array_var($args, 'extra_conditions'); } else { $SQL_EXTRA_CONDITIONS = ''; } $SQL_COLUMNS = implode(',', $select_columns); if (logged_user() instanceof Contact) { $uid = logged_user()->getId(); // Build Main SQL $logged_user_pgs = implode(',', logged_user()->getPermissionGroupIds()); $permissions_condition = "o.id IN (\r\n\t\t\t\t\tSELECT sh.object_id FROM " . TABLE_PREFIX . "sharing_table sh\r\n\t\t\t\t\tWHERE o.id = sh.object_id\r\n\t\t\t\t\tAND sh.group_id IN ({$logged_user_pgs})\r\n\t\t\t)"; /* * Check that the objects to list does not belong only to a non-manageable dimension that defines permissions * Object can be shown if: * 1 - It belongs to at least a member in a dimension that defines permissions and is manageable * 2 - Or it belongs to at least a member in a dimension that does not defines permissions * 3 - Or user has permissions to read objects without classification */ if (!$type instanceof ObjectType || !$type->getName() == 'mail') { $without_perm_dim_ids = Dimensions::findAll(array('id' => true, 'conditions' => "defines_permissions=0")); $no_perm_dims_cond = ""; if (count($without_perm_dim_ids) > 0) { $no_perm_dims_cond = " OR EXISTS (\r\n\t\t\t\t\tselect * from " . TABLE_PREFIX . "object_members omems\r\n\t\t\t\t\t inner join " . TABLE_PREFIX . "members mems on mems.id = omems.member_id\r\n\t\t\t\t\t WHERE omems.object_id=o.id AND mems.dimension_id IN (" . implode(',', $without_perm_dim_ids) . ")\r\n\t\t\t\t)"; } $permissions_condition .= " AND (\r\n\t\t\t\tEXISTS (\r\n\t\t\t\t\tSELECT cmp.permission_group_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp \r\n\t\t\t\t\tWHERE cmp.member_id=0 AND cmp.permission_group_id=" . logged_user()->getPermissionGroupId() . " AND cmp.object_type_id = o.object_type_id\r\n\t\t\t\t)\r\n\t\t\t\tOR\r\n\t\t\t\tEXISTS (\r\n\t\t\t\t\tselect * from " . TABLE_PREFIX . "object_members omems\r\n\t\t\t\t\t\tinner join " . TABLE_PREFIX . "members mems on mems.id = omems.member_id\r\n\t\t\t\t\t\tinner join " . TABLE_PREFIX . "dimensions dims on dims.id = mems.dimension_id\r\n\t\t\t\t\tWHERE omems.object_id=o.id and dims.defines_permissions=1 and dims.is_manageable=1\r\n\t\t\t\t) {$no_perm_dims_cond}\r\n\t\t\t)"; } /********************************************************************************************************/ if (!$this instanceof MailContents && logged_user()->isAdministrator() || $this instanceof Contacts && $this->object_type_name == 'contact' && can_manage_contacts(logged_user())) { $permissions_condition = "true"; } if ($this instanceof ProjectFiles && logged_user()->isAdministrator() && Plugins::instance()->isActivePlugin('mail')) { $permissions_condition = "IF(e.mail_id > 0,\r\n\t\t\t\t\t e.mail_id IN (\r\n\t\t\t\t\t\t\t\t\t\tSELECT sh.object_id FROM " . TABLE_PREFIX . "sharing_table sh\r\n\t\t\t\t\t\t\t\t\t\tWHERE e.mail_id = sh.object_id\r\n\t\t\t\t\t\t\t\t\t\tAND sh.group_id IN ({$logged_user_pgs})\r\n\t\t\t\t\t ),\r\n\t\t\t\t\t true\r\n\t\t\t\t\t)"; } if ($template_objects) { $permissions_condition = "true"; $SQL_BASE_JOIN .= " INNER JOIN " . TABLE_PREFIX . "template_tasks temob ON temob.object_id = o.id "; } $sql = "\r\n\t\t\t\tSELECT {$SQL_FOUND_ROWS} {$SQL_COLUMNS} FROM " . TABLE_PREFIX . "objects o\r\n\t\t\t\t{$SQL_BASE_JOIN}\r\n\t\t\t\t{$SQL_EXTRA_JOINS}\r\n\t\t\t\tWHERE\r\n\t\t\t\t\t{$permissions_condition}\r\n\t\t\t\t\tAND\t{$SQL_CONTEXT_CONDITION}\r\n\t\t\t\t\tAND {$SQL_TYPE_CONDITION}\r\n\t\t\t\t\tAND {$SQL_TRASHED_CONDITION} {$SQL_ARCHIVED_CONDITION} {$SQL_EXTRA_CONDITIONS}\r\n\t\t\t\t{$SQL_GROUP_BY}\r\n\t\t\t\t{$SQL_ORDER}\r\n\t\t\t\t{$SQL_LIMIT}"; if (isset($args['query_wraper_start'])) { $query_wraper_start = $args['query_wraper_start']; $query_wraper_end = $args['query_wraper_end']; $sql = $query_wraper_start . $sql . $query_wraper_end; } $sql_total = "\r\n\t\t\t\tSELECT count(o.id) as total FROM " . TABLE_PREFIX . "objects o\r\n\t\t\t\t{$SQL_BASE_JOIN}\r\n\t\t\t\t{$SQL_EXTRA_JOINS}\r\n\t\t\t\tWHERE\r\n\t\t\t\t\t{$permissions_condition}\r\n\t\t\t\t\tAND\t{$SQL_CONTEXT_CONDITION}\r\n\t\t\t\t\tAND {$SQL_TYPE_CONDITION}\r\n\t\t\t\t\tAND {$SQL_TRASHED_CONDITION} {$SQL_ARCHIVED_CONDITION} {$SQL_EXTRA_CONDITIONS}\r\n\t\t\t\t{$SQL_GROUP_BY}\t\t\t\r\n\t\t\t"; if (!$only_count_results) { // Execute query and build the resultset $rows = DB::executeAll($sql); if ($return_raw_data) { $result->objects = $rows; } else { if ($rows && is_array($rows)) { foreach ($rows as $row) { if ($handler_class) { $phpCode = '$co = ' . $handler_class . '::instance()->loadFromRow($row);'; eval($phpCode); } if ($co) { $result->objects[] = $co; } } } } if ($count_results) { $total = DB::executeOne($sql_total); $result->total = $total['total']; } else { if (count($result->objects) >= $limit) { $result->total = 10000000; } else { $result->total = $start + count($result->objects); } } } else { $total = DB::executeOne($sql_total); $result->total = $total['total']; } } else { $result->objects = array(); $result->total = 0; } return $result; }
function buildMemberList($all_members, $dimension, $allowed_member_type_ids, $allowed_object_type_ids, $item_object, $object_type_id, $return_only_name=false) { $dot_array = array(); // Dimension Object Types array (cache) $membersset = array(); foreach ($all_members as $m) { $membersset[$m->getId()] = true; } $members = array(); foreach ($all_members as $m) { /* @var $m Member */ if ($m->getArchivedById() > 0) continue; if ($object_type_id != null){ $selectable = in_array($m->getObjectTypeId(), $allowed_object_type_ids) ? true : false; if ($selectable && isset($item_object)) { if (! $item_object->canAdd(logged_user(), array($m)) ) continue; } }else{ $selectable = true ; } if ( count($allowed_member_type_ids) && !in_array($m->getObjectTypeId(), $allowed_member_type_ids) ) { continue; } $tempParent = $m->getParentMemberId(); $x = $m; while ($x instanceof Member && !isset($membersset[$tempParent])) { $tempParent = $x->getParentMemberId(); if ($x->getParentMemberId() == 0) break; $x = $x->getParentMember(); } if (!$x instanceof Member) { $tempParent = 0; } $memberOptions = ''; // SET member options (dimension object types table) // CHeck dot cache, if not set goto database and add to cache if ( empty($dot_array[$dimension->getId()]) || empty ($dot_array[$dimension->getId()][$m->getObjectTypeId()]) ) { $dot = DimensionObjectTypes::instance()->findOne(array("conditions" =>"dimension_id = ".$dimension->getId() ." AND object_type_id = ".$m->getObjectTypeId())); if ($dot instanceof DimensionObjectType){ if (empty($dot_array['dimension_id'])) { $dot_array[$dimension->getId()] = array(); } $dot_array[$dimension->getId()][$m->getObjectTypeId()] = $dot; } } if ( !empty($dot_array[$dimension->getId()]) || ($dot_array[$dimension->getId()][$m->getObjectTypeId()]) instanceof DimensionObjectType ) { $dot = $dot_array[$dimension->getId()][$m->getObjectTypeId()]; $memberOptions = $dot->getOptions(true); } if ($return_only_name) { $path = trim($m->getPath()); $member = array( "id" => $m->getId(), "name" => $m->getName(), "path" => $path, "to_show" => $m->getName() . ($path != "" ? " ($path)" : ""), "dim" => $m->getDimensionId(), "ico" => $m->getIconClass(), ); } else { /* @var $m Member */ $member = array( "id" => $m->getId(), "name" => clean($m->getName()), "parent" => $tempParent, "realParent" => $m->getParentMemberId(), "object_id" => $m->getObjectId(), "options" => $memberOptions, "depth" => $m->getDepth(), "iconCls" => $m->getIconClass(), "selectable" => isset($selectable) ? $selectable : false, "dimension_id" => $m->getDimensionId(), "object_type_id" => $m->getObjectTypeId(), "allow_childs" => $m->allowChilds() ); // Member Actions if (can_manage_dimension_members(logged_user())){ $editUrl = ''; // If member has an object linked, take object edit url if ($ot = ObjectTypes::findById($m->getObjectTypeId())) { if ($handler = $ot->getHandlerClass() ){ eval ("\$itemClass = $handler::instance()->getItemClass();"); if ($itemClass) { $instance = new $itemClass(); $instance->setId($m->getObjectId()); $instance->setObjectId($m->getObjectId()); if ($instance instanceof Contact) { if ($ot->getName() == 'company') $instance->setIsCompany(1); } $editUrl = $instance->getEditUrl(); } } } // Take default membewr edit url if not overwitten if (!$editUrl) { $editUrl = get_url('member', 'edit', array('id'=> $m->getId())); } $member['actions'] = array(array( 'url' => $editUrl, 'text' => '', 'iconCls' => 'ico-edit', 'class' => 'action-edit' )); } } $members[] = $member; } // re-sort by parent and name $tmp_members = array(); foreach ($members as $m) { $tmp_members[array_var($m, 'parent') . strtolower(array_var($m, 'name')) . array_var($m, 'id')] = $m; } ksort($tmp_members, SORT_STRING); $members = $tmp_members; return $members ; }
function get_dimensions_for_properties() { if (!can_manage_dimension_members(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $dim_id = get_id(); $obj_type = get_id('otype'); $parent_id = get_id('parent'); if ($parent_id == 0) { $dim_obj_type = DimensionObjectTypes::findById(array('dimension_id' => $dim_id, 'object_type_id' => $obj_type)); if (!$dim_obj_type->getIsRoot()) { flash_error(lang('parent member must be selected to set properties')); ajx_current("empty"); return; } } $dimensions = array(); $associations_info = array(); $associations_info_tmp = array(); $member_parents = array(); $associations = DimensionMemberAssociations::getAssociatations($dim_id, $obj_type); foreach ($associations as $assoc) { $assoc_info = array('id' => $assoc->getId(), 'required' => $assoc->getIsRequired(), 'multi' => $assoc->getIsMultiple(), 'ot' => $assoc->getAssociatedObjectType()); $assoc_info['members'] = Members::getByDimensionObjType($assoc->getAssociatedDimensionMemberAssociationId(), $assoc->getAssociatedObjectType()); $ot = ObjectTypes::findById($assoc->getAssociatedObjectType()); $assoc_info['ot_name'] = $ot->getName(); if (!isset($associations_info_tmp[$assoc->getAssociatedDimensionMemberAssociationId()])) { $associations_info_tmp[$assoc->getAssociatedDimensionMemberAssociationId()] = array(); $dimensions[] = Dimensions::getDimensionById($assoc->getAssociatedDimensionMemberAssociationId()); } $associations_info_tmp[$assoc->getAssociatedDimensionMemberAssociationId()][] = $assoc_info; } // check for restrictions if ($parent_id > 0) { $parent = Members::findById($parent_id); $all_parents = $parent->getAllParentMembersInHierarchy(); $all_parent_ids = array($parent_id); foreach ($all_parents as $p) { $all_parent_ids[] = $p->getId(); } } else { $all_parent_ids = array(0); } $all_property_members = array(); foreach ($associations_info_tmp as $assoc_dim => $ot_infos) { foreach ($ot_infos as $info) { $restriction_defs = DimensionMemberRestrictionDefinitions::findAll(array("conditions" => "`dimension_id` = {$dim_id} AND `restricted_dimension_id` = {$assoc_dim} \n\t\t\t\t\tAND `restricted_object_type_id` = " . $info['ot'])); if (!is_array($restriction_defs) || count($restriction_defs) == 0) { // no restriction definitions => include all members $associations_info[$assoc_dim][] = $info; $restricted_dimensions[$assoc_dim] = false; } else { // restriction definition found => filter members $restricted_dimensions[$assoc_dim] = true; $restrictions = array(); $rest_members = array(); $conditions = ""; foreach ($restriction_defs as $rdef) { $conditions = "`restricted_member_id` IN (SELECT `id` FROM " . Members::instance()->getTableName(true) . " WHERE \n\t\t\t\t\t\t\t`object_type_id` = " . $rdef->getRestrictedObjectTypeId() . " AND `dimension_id` = {$assoc_dim}) AND `member_id` IN (" . implode(",", $all_parent_ids) . ")"; $restrictions[] = MemberRestrictions::findAll(array("conditions" => $conditions)); } $to_intersect = array(); foreach ($restrictions as $k => $rests) { $to_intersect[$k] = array(); foreach ($rests as $rest) { $to_intersect[$k][] = $rest->getRestrictedMemberId(); } if (count($to_intersect[$k]) == 0) { unset($to_intersect[$k]); } } $apply_filter = true; $intersection = array_var($to_intersect, 0, array()); if (count($to_intersect) > 1) { $k = 1; while ($k < count($to_intersect)) { $intersection = array_intersect($intersection, $to_intersect[$k++]); } } else { if (count($to_intersect) == 0) { // no restrictions found for members $apply_filter = false; } } if ($apply_filter) { $rest_members = Members::findAll(array("conditions" => "`id` IN (" . implode(",", $intersection) . ")")); } else { $rest_members = $info['members']; } $new_info = $info; $new_info['members'] = $rest_members; $associations_info[$assoc_dim][] = $new_info; foreach ($rest_members as $member) { if (!isset($member_parents[$assoc_dim])) { $member_parents[$assoc_dim] = array(); } if ($member->getParentMemberId() > 0) { $member_parents[$assoc_dim][$member->getId()] = $member->getParentMemberId(); } } } } } foreach ($associations_info as $assoc_dim => $ot_infos) { foreach ($ot_infos as $info) { foreach ($info['members'] as $mem) { $all_property_members[] = $mem->getId(); } } } // para cada $info['ot'] ver si en el resultado hay miembros que los restringen foreach ($associations_info as $assoc_dim => &$ot_infos) { foreach ($ot_infos as &$info) { $restriction_defs = DimensionMemberRestrictionDefinitions::findAll(array("conditions" => "`restricted_dimension_id` = {$assoc_dim} \n\t\t\t\t\tAND `restricted_object_type_id` = " . $info['ot'])); $restrictions = array(); foreach ($restriction_defs as $rdef) { $restrictions_tmp = MemberRestrictions::findAll(array("conditions" => "`member_id` IN (\n\t\t\t\t\t\tSELECT `id` FROM " . Members::instance()->getTableName(true) . " WHERE `dimension_id` = " . $rdef->getDimensionId() . " AND `object_type_id` = " . $rdef->getObjectTypeId() . " AND `id` IN (" . implode(",", $all_property_members) . "))")); $restrictions = array_merge($restrictions, $restrictions_tmp); } $restricted_ids = array(); if (count($restrictions) == 0) { continue; } foreach ($restrictions as $rest) { $restricted_ids[] = $rest->getRestrictedMemberId(); } $tmp = array(); foreach ($info['members'] as $rmem) { if (in_array($rmem->getId(), $restricted_ids)) { $tmp[] = $rmem; } } $info['members'] = $tmp; } } $req_dimensions = array(); foreach ($associations_info as $assoc_dim => &$ot_infos) { $required_count = 0; foreach ($ot_infos as &$info) { if ($info['required']) { $required_count++; } } $req_dimensions[$assoc_dim] = $required_count > 0; } $member_id = get_id('mem_id'); $actual_associations_info = array(); if ($member_id > 0) { // actual associations $actual_associations = MemberPropertyMembers::getAssociatedPropertiesForMember($member_id); foreach ($actual_associations as $actual_assoc) { $actual_associations_info[$actual_assoc->getPropertyMemberId()] = true; } } tpl_assign('genid', array_var($_GET, 'genid')); tpl_assign('dimensions', $dimensions); tpl_assign('associations', $associations_info); tpl_assign('actual_associations', $actual_associations_info); tpl_assign('req_dimensions', $req_dimensions); tpl_assign('restricted_dimensions', isset($restricted_dimensions) ? $restricted_dimensions : array()); ajx_extra_data(array('parents' => $member_parents, 'genid' => array_var($_GET, 'genid'))); $this->setTemplate('dim_properties'); }
function getObjectTypeName(){ if (!$this->object_type) $this->object_type = ObjectTypes::findById($this->getObjectTypeId()); return $this->object_type instanceof ObjectType ? $this->object_type->getName() : ""; }
?> </th></tr> <?php $last_dim = 0; $isAlt = true; foreach ($dimension_ots as $dimension_ot) { $dim_changed = $last_dim != $dimension_ot->getDimensionId(); if ($dim_changed) { $isAlt = !$isAlt; } $dimension = Dimensions::getDimensionById($dimension_ot->getDimensionId()); if (!$dimension instanceof Dimension || !$dimension->getIsManageable()) { continue; } $dimension_name = $dimension->getName(); $ot = ObjectTypes::findById($dimension_ot->getObjectTypeId()); if (!$ot instanceof ObjectType || in_array($ot->getName(), array('customer_folder', 'project_folder'))) { continue; } $ot_name = lang($ot->getName()); ?> <tr class="<?php echo ($isAlt ? 'altRow ' : '') . ($dim_changed ? 'bordered-top' : ''); ?> "> <td><?php echo $dim_changed ? $dimension_name : ""; ?> </td>
function getActivityDataView($user, $object, $made_several_changes = false) { if (!$user) { return false; } $userName = "******" . $user->getObjectName() . "</b>"; $icon_class = ""; if ($object instanceof ProjectFile) { $path = explode("-", str_replace(".", "_", str_replace("/", "-", $object->getTypeString()))); $acc = ""; foreach ($path as $p) { $acc .= $p; $icon_class .= ' ico-' . $acc; $acc .= "-"; } } // Build data depending on type if ($object instanceof ContentDataObject) { if ($object instanceof Contact && $object->isUser()) { $type = "user"; } else { $type = $object->getObjectTypeName(); } if ($type != 'Time' || $type == 'Time' && $object->getRelObjectId() != 0) { $object_link = '<br /><a style="font-weight:bold" href="' . $object->getObjectUrl() . '">' . '<span style="padding: 2px 0 3px 24px;" class="link-ico ico-unknown ico-' . $type . $icon_class . '"/>' . clean($object->getObjectName()) . '</a>'; } else { //if it is a general timeslot $object_link = '<span style="padding: 1px 0 3px 18px; font-weight:bold;" class="db-ico ico-unknown ico-' . $type . $icon_class . '"/>' . clean($object->getObjectName()); } } elseif ($object instanceof Member) { $object_type = ObjectTypes::findById($object->getObjectTypeId()); $type = $object_type->getName(); $object_url = ""; $onclick = ""; switch ($type) { case "folder": $onclick = "og.crpm.onFolderClick(" . $object->getId() . ");"; break; case "project": $onclick = "og.projects.onProjectClick(" . $object->getId() . ");"; break; case "customer": $onclick = "og.customers.onCustomerClick(" . $object->getId() . ");"; break; case "workspace": $onclick = "og.workspaces.onWorkspaceClick(" . $object->getId() . ");"; break; default: $onclick = ""; } $object_link = '<br /><a class="internalLink" href="javascript:void(0);" onclick="' . $onclick . '">' . '<span style="padding: 1px 0 3px 18px;" class="db-ico ico-unknown ico-' . $type . $icon_class . '"/>' . clean($this->getObjectName()) . '</a>'; return lang('activity ' . $this->getAction(), lang('the ' . $type, " "), $userName, $object_link); } else { $object_link = '<br />' . clean($this->getObjectName()) . ' ' . lang('object is deleted'); return lang('activity ' . $this->getAction(), "", $userName, $object_link); } if ($made_several_changes) { $this->setAction(ApplicationLogs::ACTION_MADE_SEVERAL_CHANGES); } switch ($this->getAction()) { case ApplicationLogs::ACTION_MADE_SEVERAL_CHANGES: /*$object_history = '<a style="font-weight:bold" href="' . $object->getViewHistoryUrl() . '"> '. '<span style="padding: 1px 0 3px 18px;" class="db-ico ico-unknown ico-history"/>'.lang('view history').'</a>';*/ return lang('activity ' . $this->getAction(), lang('the ' . $type . ' activity', $object_link), $userName, ""); case ApplicationLogs::ACTION_EDIT: case ApplicationLogs::ACTION_ADD: case ApplicationLogs::ACTION_DELETE: case ApplicationLogs::ACTION_TRASH: case ApplicationLogs::ACTION_UNTRASH: case ApplicationLogs::ACTION_OPEN: case ApplicationLogs::ACTION_CLOSE: case ApplicationLogs::ACTION_ARCHIVE: case ApplicationLogs::ACTION_UNARCHIVE: case ApplicationLogs::ACTION_READ: case ApplicationLogs::ACTION_DOWNLOAD: case ApplicationLogs::ACTION_UPLOAD: case ApplicationLogs::ACTION_CHECKIN: case ApplicationLogs::ACTION_CHECKOUT: if ($object instanceof ContentDataObject) { return lang('activity ' . $this->getAction(), lang('the ' . $type, " "), $userName, $object_link); } case ApplicationLogs::ACTION_SUBSCRIBE: case ApplicationLogs::ACTION_UNSUBSCRIBE: $user_ids = explode(",", $this->getLogData()); if (count($user_ids) < 8) { $users_str = ""; foreach ($user_ids as $usid) { $su = Contacts::findById($usid); if ($su instanceof Contact) { $users_str .= '<a style="font-weight:bold" href="' . $su->getObjectUrl() . '"> <span style="padding: 0 0 3px 18px;" class="db-ico ico-unknown ico-user"/>' . clean($su->getObjectName()) . '</a>, '; } } if (count($user_ids) == 1) { $users_text = substr(trim($users_str), 0, -1); } else { $users_text = lang('x users', count($user_ids), ": {$users_str}"); } } else { $users_text = lang('x users', count($user_ids), ""); } if ($object instanceof ContentDataObject) { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName(), " "), $userName, $object_link, $users_text); } case ApplicationLogs::ACTION_COMMENT: if ($object instanceof ContentDataObject) { $rel_object = Objects::findObject($this->getRelObjectId()); $commented_object = null; if ($rel_object instanceof Comment) { $commented_object = $rel_object->getRelObject(); } $obj_type_name = $commented_object instanceof ContentDataObject ? $commented_object->getObjectTypeName() : $rel_object->getObjectTypeName(); $comentText = $this->getLogData(); return lang('activity ' . $this->getAction(), lang('the ' . $obj_type_name, " "), $userName, $object_link, $comentText); } case ApplicationLogs::ACTION_LINK: case ApplicationLogs::ACTION_UNLINK: $linked_object_link = ''; $linked_object = Objects::findObject($this->getLogData()); if ($linked_object instanceof ApplicationDataObject) { $icon_class = ""; if ($linked_object instanceof ProjectFile) { $path = explode("-", str_replace(".", "_", str_replace("/", "-", $linked_object->getTypeString()))); $acc = ""; foreach ($path as $p) { $acc .= $p; $icon_class .= ' ico-' . $acc; $acc .= "-"; } } $linked_object_link = '<a style="font-weight:bold" href="' . $linked_object->getObjectUrl() . '"> <span style="padding: 1px 0 3px 18px;" class="db-ico ico-unknown ico-' . $linked_object->getObjectTypeName() . $icon_class . '"/>' . clean($linked_object->getObjectName()) . '</a>'; } if ($object instanceof ContentDataObject) { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName(), " "), $userName, $object_link, $linked_object instanceof ApplicationDataObject ? lang('the ' . $linked_object->getObjectTypeName()) : '', $linked_object_link); } case ApplicationLogs::ACTION_LOGIN: case ApplicationLogs::ACTION_LOGOUT: return lang('activity ' . $this->getAction(), $userName); case ApplicationLogs::ACTION_MOVE: $from_to = explode(";", $this->getLogData()); $to = ""; $from = ""; if (is_array($from_to) && count($from_to) > 0) { foreach ($from_to as $fr_to) { if (strpos($fr_to, 'from:') !== FALSE) { $from = $fr_to; } elseif (strpos($fr_to, 'to:') !== FALSE) { $to = $fr_to; } } } //to $to_str = ""; $to_str_member = ""; $members_ids_csv = str_replace("to:", "", $to); $mem_ids = explode(",", $members_ids_csv); if (is_array($mem_ids) && count($mem_ids) > 0) { foreach ($mem_ids as $mem_id) { $member = Members::findById($mem_id); if ($member) { $to_str_member .= $member->getName() . ", "; } } if ($to_str_member != "") { $to_str_member = substr($to_str_member, 0, -2); $to_str .= $to_str_member; } } //from $from_str = ""; $from_str_member = ""; $members_ids_csv_from = str_replace("from:", "", $from); $mem_ids_from = explode(",", $members_ids_csv_from); if (is_array($mem_ids_from) && count($mem_ids_from) > 0) { foreach ($mem_ids_from as $mem_id) { $member = Members::findById($mem_id); if ($member) { $from_str_member .= $member->getName() . ", "; } } if ($from_str_member != "") { $from_str_member = substr($from_str_member, 0, -2); $from_str .= $from_str_member; } } if ($object instanceof ContentDataObject) { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' from to', lang('the ' . $object->getObjectTypeName()), $userName, $object_link, $from_str, $to_str); } } else { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' from to', lang('the ' . $this->getRelObjectManager()), $userName, $object_link, $from_str, $to_str); } } case ApplicationLogs::ACTION_COPY: $to_str = ""; $to_str_member = ""; $members_ids_csv = str_replace("to:", "", $this->getLogData()); $mem_ids = explode(",", $members_ids_csv); if (is_array($mem_ids) && count($mem_ids) > 0) { foreach ($mem_ids as $mem_id) { $member = Members::findById($mem_id); if ($member) { $to_str_member .= $member->getName() . ", "; } } if ($to_str_member != "") { $to_str_member = substr($to_str_member, 0, -2); $to_str .= $to_str_member; } } if ($object instanceof ContentDataObject) { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' to', lang('the ' . $object->getObjectTypeName()), $userName, $object_link, $to_str); } } else { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' to', lang('the ' . $this->getRelObjectManager()), $userName, $object_link, $to_str); } } default: return $this->getAction(); false; } return $this->getAction(); false; }