public static function create(array $attributes)
 {
     $model = new ObjectTypes();
     $model->fill($attributes);
     $model->save();
     return $model;
 }
Пример #2
0
 function getObjectTypeName()
 {
     if (!$this->object_type) {
         $this->object_type = ObjectTypes::findById($this->getObjectTypeId());
     }
     return $this->object_type->getName();
 }
Пример #3
0
function workspaces_override_member_color($member, &$color) {
	
	$ws_ot = ObjectTypes::findByName('workspace');
	if (!$ws_ot instanceof ObjectType) return;
	
	if ($member->getObjectTypeId() == $ws_ot->getId()) {
		$ws = Workspaces::getWorkspaceById($member->getObjectId());
		if ($ws instanceof Workspace) {
			$color = $ws->getColumnValue('color');
		}
	}
}
Пример #4
0
function workspaces_update_5_6()
{
    // create associations
    DB::execute("\n\t\t\tINSERT INTO `" . TABLE_PREFIX . "dimension_member_associations` (`dimension_id`,`object_type_id`,`associated_dimension_id`, `associated_object_type_id`, `is_required`,`is_multiple`, `keeps_record`) VALUES\n\t\t\t((SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'workspaces'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'workspace'),(SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'feng_persons'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'person' LIMIT 1),0,1,0),\n\t\t\t((SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'workspaces'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'workspace'),(SELECT id from " . TABLE_PREFIX . "dimensions WHERE code = 'feng_persons'),(SELECT id FROM " . TABLE_PREFIX . "object_types WHERE name = 'company' LIMIT 1),0,1,0);\n\t\t");
    // instantiate actual associations
    $ws_dim = Dimensions::findByCode('workspaces');
    $ws_ot = ObjectTypes::findByName('workspace');
    $ws_members = Members::findAll(array('conditions' => 'dimension_id = ' . $ws_dim->getId() . ' AND object_type_id = ' . $ws_ot->getId()));
    foreach ($ws_members as $ws_mem) {
        // after saving permissions the associations are instantiated by 'core_dimensions' plugin
        save_member_permissions($ws_mem);
    }
}
Пример #5
0
 static function getListableObjectTypeIds()
 {
     if (is_null(self::$listableObjectTypesIds)) {
         $ids = array();
         $sql = "\n\t\t\t\tSELECT DISTINCT(id) as id  \n\t\t\t\tFROM " . TABLE_PREFIX . "object_types \n\t\t\t\tWHERE type IN ('content_object', 'dimension_object') AND (\n\t\t\t\t\tplugin_id IS NULL OR \n\t\t\t\t\tplugin_id = 0 OR \n\t\t\t\t\tplugin_id IN ( \n\t\t\t\t\t\tSELECT id FROM " . TABLE_PREFIX . "plugins WHERE is_activated > 0 AND is_installed > 0 \n\t\t\t\t\t)\n\t\t\t\t)";
         $rows = DB::executeAll($sql);
         foreach ($rows as $row) {
             $ids[array_var($row, 'id')] = array_var($row, 'id');
         }
         self::$listableObjectTypesIds = $ids;
     }
     return self::$listableObjectTypesIds;
 }
 /**
  * Render form control
  *
  * @param string $control_name
  * @return string
  */
 function render($control_name)
 {
     $options = array();
     $contact_types[] = array(ObjectTypes::findByName("contact")->getId(), lang("contact"));
     $contact_types[] = array(ObjectTypes::findByName("company")->getId(), lang("company"));
     $unknown_id = 0;
     $option_attributes = $this->getRawValue() == $unknown_id ? array('selected' => 'selected') : null;
     $options[] = option_tag(lang("unknown"), $unknown_id, $option_attributes);
     $contact_id = ObjectTypes::findByName("contact")->getId();
     $option_attributes = $this->getRawValue() == $contact_id ? array('selected' => 'selected') : null;
     $options[] = option_tag(lang("contact"), $contact_id, $option_attributes);
     $company_id = ObjectTypes::findByName("company")->getId();
     $option_attributes = $this->getRawValue() == $company_id ? array('selected' => 'selected') : null;
     $options[] = option_tag(lang("company"), $company_id, $option_attributes);
     return select_box($control_name, $options);
 }
 function render($control_name)
 {
     $genid = gen_id();
     $object_types = ObjectTypes::getAvailableObjectTypes();
     $value = $this->getValue();
     $out = '';
     foreach ($object_types as $ot) {
         $checked = array_search($ot->getId(), $value) !== false;
         $out .= '<div  class="checkbox-config-option">';
         $out .= label_tag(lang($ot->getName()), $genid . '_' . $control_name . '_' . $ot->getId(), false, array('style' => 'cursor:pointer;'), '');
         $out .= checkbox_field($control_name . '[' . $ot->getId() . ']', $checked, array('id' => $genid . '_' . $control_name . '_' . $ot->getId()));
         $out .= '</div >';
     }
     $out .= '<input type="hidden" name="' . $control_name . '[0]" value=" "><div class="clear"></div>';
     return $out;
 }
 function render($control_name)
 {
     $genid = gen_id();
     $object_types = ObjectTypes::getAvailableObjectTypesWithDimensionObjects(" AND `name` IN ('task', 'project', 'sample')");
     $value = $this->getValue();
     $out = '';
     foreach ($object_types as $ot) {
         $checked = array_search($ot->getId(), $value) !== false;
         $out .= '<div style="float:left; margin-right: 15px; min-width: 130px;">';
         $out .= label_tag(lang($ot->getName()), $genid . '_' . $control_name . '_' . $ot->getId(), false, array('style' => 'cursor:pointer;'), '');
         $out .= checkbox_field($control_name . '[' . $ot->getId() . ']', $checked, array('id' => $genid . '_' . $control_name . '_' . $ot->getId()));
         $out .= '</div >';
     }
     $out .= '<input type="hidden" name="' . $control_name . '[0]" value=" "><div class="clear"></div>';
     return $out;
 }
Пример #9
0
 private function list_members($request)
 {
     $service = $request['srv'];
     $members = array();
     $type = ObjectTypes::instance()->findByName($service);
     $typeId = $type->getId();
     $ids = array();
     $dimensionController = new DimensionController();
     foreach ($dimensionController->initial_list_dimension_members(Dimensions::findByCode('customer_project')->getId(), $typeId) as $member) {
         $ids[] = $member['object_id'];
     }
     if (count($ids)) {
         $args['conditions'] = " `object_id` IN (" . implode(",", $ids) . ") AND object_type_id = {$typeId}";
         foreach (Members::instance()->findAll($args) as $member) {
             /* @var $member Member */
             $memberInfo = array('id' => $member->getId(), 'name' => $member->getName(), 'type' => $service, 'path' => $member->getPath());
             $members[] = $memberInfo;
         }
     }
     return $this->response('json', $members);
 }
Пример #10
0
function core_dim_add_new_contact_to_person_dimension($object)
{
    /* @var $object Contact */
    $person_ot = ObjectTypes::findOne(array("conditions" => "`name` = 'person'"));
    $company_ot = ObjectTypes::findOne(array("conditions" => "`name` = 'company'"));
    $person_dim = Dimensions::findOne(array("conditions" => "`code` = 'feng_persons'"));
    if ($person_ot instanceof ObjectType && $person_dim instanceof Dimension) {
        $oid = $object->isCompany() ? $company_ot->getId() : $person_ot->getId();
        $tmp_mem = Members::findOne(array("conditions" => "`dimension_id` = " . $person_dim->getId() . " AND `object_type_id` = {$oid} AND `object_id` = " . $object->getId()));
        $reload_dimension = true;
        if ($tmp_mem instanceof Member) {
            $member = $tmp_mem;
            $reload_dimension = false;
        } else {
            $member = new Member();
            $member->setName($object->getObjectName());
            $member->setDimensionId($person_dim->getId());
            $parent_member_id = 0;
            $depth = 1;
            if ($object->isCompany()) {
                $member->setObjectTypeId($company_ot->getId());
            } else {
                $member->setObjectTypeId($person_ot->getId());
                if ($object->getCompanyId() > 0) {
                    $pmember = Members::findOne(array('conditions' => '`object_id` = ' . $object->getCompanyId() . ' AND `object_type_id` = ' . $company_ot->getId() . ' AND `dimension_id` = ' . $person_dim->getId()));
                    if ($pmember instanceof Member) {
                        $parent_member_id = $pmember->getId();
                        $depth = $pmember->getDepth() + 1;
                    }
                }
            }
            $member->setParentMemberId($parent_member_id);
            $member->setDepth($depth);
            $member->setObjectId($object->getId());
            $member->save();
        }
        $sql = "INSERT INTO `" . TABLE_PREFIX . "contact_dimension_permissions` (`permission_group_id`, `dimension_id`, `permission_type`)\n\t\t\t\t SELECT `c`.`permission_group_id`, " . $person_dim->getId() . ", 'check'\n\t\t\t\t FROM `" . TABLE_PREFIX . "contacts` `c` \n\t\t\t\t WHERE `c`.`is_company`=0 AND `c`.`user_type`!=0 AND `c`.`disabled`=0 AND `c`.`object_id`=" . $object->getId() . "\n\t\t\t\t ON DUPLICATE KEY UPDATE `dimension_id`=`dimension_id`;";
        DB::execute($sql);
        $sql = "INSERT INTO `" . TABLE_PREFIX . "contact_member_permissions` (`permission_group_id`, `member_id`, `object_type_id`, `can_write`, `can_delete`)\n\t\t\t\t SELECT `c`.`permission_group_id`, " . $member->getId() . ", `ot`.`id`, (`c`.`object_id` = " . $object->getId() . ") as `can_write`, (`c`.`object_id` = " . $object->getId() . ") as `can_delete`\n\t\t\t\t FROM `" . TABLE_PREFIX . "contacts` `c` JOIN `" . TABLE_PREFIX . "object_types` `ot` \n\t\t\t\t WHERE `c`.`is_company`=0 AND `c`.`object_id`=" . $object->getId() . "\n\t\t\t\t \tAND `c`.`user_type`!=0 AND `c`.`disabled`=0\n\t\t\t\t\tAND `ot`.`type` IN ('content_object', 'comment')\n\t\t\t\t ON DUPLICATE KEY UPDATE `member_id`=`member_id`;";
        DB::execute($sql);
        DB::execute("DELETE FROM `" . TABLE_PREFIX . "contact_member_permissions` WHERE `permission_group_id` = 0;");
        // NEW! Add contact to its own member to be searchable
        if (logged_user() instanceof Contact) {
            $ctrl = new ObjectController();
            $ctrl->add_to_members($object, array($member->getId()));
        } else {
            $object->addToMembers(array($member));
            $object->addToSharingTable();
        }
        // add permission to creator
        if ($object->getCreatedBy() instanceof Contact) {
            DB::execute("INSERT INTO `" . TABLE_PREFIX . "contact_member_permissions` (`permission_group_id`, `member_id`, `object_type_id`, `can_write`, `can_delete`)\n\t\t\t\t SELECT " . $object->getCreatedBy()->getPermissionGroupId() . ", " . $member->getId() . ", `ot`.`id`, 1, 1\n\t\t\t\t FROM `" . TABLE_PREFIX . "object_types` `ot` \n\t\t\t\t WHERE `ot`.`type` IN ('content_object', 'comment')\n\t\t\t\t ON DUPLICATE KEY UPDATE `member_id`=`member_id`;");
        }
        if ($reload_dimension) {
            evt_add("reload dimension tree", $member->getDimensionId());
        }
    }
}
Пример #11
0
 function quick_add_form()
 {
     ajx_current("empty");
     $this->setLayout('empty');
     $dimension_id = array_var($_GET, 'dimension_id');
     $dimension = is_numeric($dimension_id) ? Dimensions::instance()->findById($dimension_id) : null;
     if ($dimension instanceof Dimension) {
         $object_Types = array();
         $parent_member_id = array_var($_GET, 'parent_member_id');
         $parent_member = Members::instance()->findById($parent_member_id);
         if ($parent_member instanceof Member) {
             $object_types = DimensionObjectTypes::getChildObjectTypes($parent_member);
             if (count($object_types) == 0) {
                 $parent_member = null;
                 $object_types = DimensionObjectTypes::instance()->findAll(array("conditions" => "enabled=1 AND dimension_id = {$dimension_id} AND is_root = 1 AND object_type_id<>(SELECT id from " . TABLE_PREFIX . "object_types WHERE name='company')"));
             }
         } else {
             $object_types = DimensionObjectTypes::instance()->findAll(array("conditions" => "enabled=1 AND dimension_id = {$dimension_id} AND is_root = 1 AND object_type_id<>(SELECT id from " . TABLE_PREFIX . "object_types WHERE name='company')"));
         }
         $obj_types = array();
         $editUrls = array();
         foreach ($object_types as $object_type) {
             $options = $object_type->getOptions(1);
             if (isset($options->defaultAjax) && $options->defaultAjax->controller != "dashboard") {
                 $editUrls[$object_type->getObjectTypeId()] = get_url($options->defaultAjax->controller, 'add');
             } else {
                 $t = ObjectTypes::instance()->findById($object_type->getObjectTypeId());
                 $obj_types[$t->getId()] = $t;
                 $class_name = ucfirst($t->getName()) . "Controller";
                 $controller_exists = controller_exists($t->getName(), $t->getPluginId());
                 if ($controller_exists) {
                     Env::useController(ucfirst($t->getName()));
                     eval('$controller = new ' . $class_name . '();');
                 }
                 if ($t && controller_exists($t->getName(), $t->getPluginId()) && $t->getHandlerClass() != '' && $controller_exists && method_exists($controller, 'add')) {
                     $params = array("type" => $t->getId());
                     if ($parent_member instanceof Member) {
                         $params['parent'] = $parent_member->getId();
                     }
                     $editUrls[$t->getId()] = get_url($t->getName(), 'add', $params);
                 } else {
                     $params = array("dim_id" => $dimension_id, "type" => $t->getId());
                     if ($parent_member instanceof Member) {
                         $params['parent'] = $parent_member->getId();
                     }
                     $editUrls[$t->getId()] = get_url('member', 'add', $params);
                 }
             }
         }
         $urls = array();
         foreach ($editUrls as $ot_id => $url) {
             $ot = array_var($obj_types, $ot_id);
             if ($ot instanceof ObjectType) {
                 $link_text = ucfirst(strtolower(lang('new ' . $ot->getName())));
                 $iconcls = $ot->getIconClass();
             } else {
                 $link_text = lang('new');
                 $iconcls = "";
             }
             $urls[] = array('link_text' => $link_text, 'url' => $url, 'iconcls' => $iconcls);
         }
         Hook::fire('member_quick_add_urls', array('dimension' => $dimension, 'object_types' => $object_types, 'parent_member' => $parent_member), $urls);
         if (count($urls) > 1) {
             ajx_extra_data(array('draw_menu' => 1, 'urls' => $urls));
         } else {
             ajx_extra_data(array('urls' => $urls));
         }
     } else {
         Logger::log("Invalid dimension: {$dimension_id}");
     }
 }
Пример #12
0
</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 ?>
 function dimension_options_submit()
 {
     ajx_current("empty");
     if (!can_manage_dimensions(logged_user())) {
         flash_error(lang('no access permissions'));
         return;
     }
     $folder_ots = ObjectTypes::findAll(array('id' => true, 'conditions' => "name IN ('folder','project_folder','customer_folder')"));
     $data = array_var($_POST, 'enabled_dots');
     $names_data = array_var($_POST, 'custom_names');
     if (is_array($data) || is_array($names_data)) {
         try {
             DB::beginWork();
             // enabled dimension object types
             foreach ($data as $dim_id => $ots_info) {
                 foreach ($ots_info as $ot_id => $enabled) {
                     DB::execute("UPDATE " . TABLE_PREFIX . "dimension_object_types SET enabled=" . DB::escape($enabled) . " \r\n\t\t\t\t\t\t\tWHERE dimension_id=" . DB::escape($dim_id) . " AND object_type_id=" . DB::escape($ot_id));
                     // if object type is folder, set the same configuration to all folder types
                     if (in_array($ot_id, $folder_ots)) {
                         DB::execute("UPDATE " . TABLE_PREFIX . "dimension_object_types SET enabled=" . DB::escape($enabled) . "\r\n\t\t\t\t\t\t\t\tWHERE dimension_id=" . DB::escape($dim_id) . " AND object_type_id IN (" . implode(',', $folder_ots) . ")");
                     }
                 }
             }
             // custom dimension names
             foreach ($names_data as $dim_id => $custom_name) {
                 $cname = trim($custom_name);
                 $dimension = Dimensions::getDimensionById($dim_id);
                 if ($dimension instanceof Dimension) {
                     $dimension->setOptionValue('custom_dimension_name', $cname);
                 }
             }
             DB::commit();
             flash_success(lang("success edit dimension options"));
             evt_add('tabs changed');
             //ajx_current("back");
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
     }
 }
Пример #14
0
 function quick_add_form()
 {
     $this->setLayout('empty');
     if ($dimension_id = array_var($_GET, 'dimension_id')) {
         $dimension = Dimensions::instance()->findById($dimension_id);
         $dimensionOptions = $dimension->getOptions(true);
         $object_Types = array();
         $parent_member_id = array_var($_GET, 'parent_member_id');
         if ($parent_member_id) {
             $parent_member = Members::instance()->findById($parent_member_id);
             $object_types = DimensionObjectTypes::getChildObjectTypes($parent_member_id);
         } else {
             $object_types = DimensionObjectTypes::instance()->findAll(array("conditions" => "dimension_id = {$dimension_id} AND is_root = 1 "));
         }
         if (count($object_types)) {
             if (count($object_types) == 1) {
                 // Input Hidden
                 tpl_assign('object_type', $object_types[0]);
                 tpl_assign('object_type_name', ObjectTypes::instance()->findById($object_types[0]->getObjectTypeId())->getName());
             } else {
                 // Input combo
                 tpl_assign('object_types', $object_types);
             }
         } else {
             tpl_assign("error_msg", $parent_member->getName() . " does not accept child nodes ");
         }
         $editUrls = array();
         foreach ($object_types as $object_type) {
             /* @var $object_type DimensionObjectType */
             if (ObjectTypes::instance()->findById($object_type->getObjectTypeId())->getType() != 'dimension_object') {
                 continue;
             }
             $options = $object_type->getOptions(1);
             if (isset($options->defaultAjax) && $options->defaultAjax->controller != "dashboard") {
                 $editUrls[$object_type->getObjectTypeId()] = get_url($options->defaultAjax->controller, 'add');
             } else {
                 $t = ObjectTypes::instance()->findById($object_type->getObjectTypeId());
                 /* @var $t ObjectType */
                 $class_name = ucfirst($t->getName()) . "Controller";
                 if ($t && controller_exists($t->getName(), $t->getPluginId())) {
                     $editUrls[$object_type->getObjectTypeId()] = get_url($t->getName(), 'add');
                 } else {
                     $editUrls[$object_type->getObjectTypeId()] = get_url('member', 'add', array("dim_id" => $dimension_id));
                 }
             }
         }
         tpl_assign('editUrls', $editUrls);
         tpl_assign('parent_member_id', $parent_member_id);
         tpl_assign('dimension_id', $dimension_id);
         if (is_object($dimensionOptions) && is_object($dimensionOptions->quickAdd) && $dimensionOptions->quickAdd->formAction) {
             tpl_assign('form_action', ROOT_URL . "/" . $dimensionOptions->quickAdd->formAction);
         } else {
             tpl_assign('form_action', get_url('member', 'add', array('quick' => '1')));
         }
     } else {
         die("SORRY. Invalid dimension");
     }
 }
Пример #15
0
?>
</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>
					
 static function addObjToSharingTable($oid, $tid, $obj_mem_ids)
 {
     $gids = array();
     $table_prefix = defined('FORCED_TABLE_PREFIX') && FORCED_TABLE_PREFIX ? FORCED_TABLE_PREFIX : TABLE_PREFIX;
     //1. clear sharing table for this object
     SharingTables::delete("object_id={$oid}");
     //2. get dimensions of this object's members that defines permissions
     $res = DB::execute("SELECT d.id as did FROM " . $table_prefix . "dimensions d INNER JOIN " . $table_prefix . "members m on m.dimension_id=d.id\r\n\t\t\t\tWHERE m.id IN ( SELECT member_id FROM " . $table_prefix . "object_members WHERE object_id = {$oid} AND is_optimization = 0 ) AND d.defines_permissions = 1");
     $dids_tmp = array();
     while ($row = $res->fetchRow()) {
         $dids_tmp[$row['did']] = $row['did'];
     }
     $res->free();
     $dids = array_values($dids_tmp);
     $dids_tmp = null;
     $sql_from = "" . $table_prefix . "contact_member_permissions cmp\r\n\t\tLEFT JOIN " . $table_prefix . "members m ON m.id = cmp.member_id\r\n\t\tLEFT JOIN " . $table_prefix . "dimensions d ON d.id = m.dimension_id";
     $member_where_conditions = "";
     $dim_where_conditions = "";
     // if users can add objects without classifying then check for permissions with member_id=0
     if (config_option('let_users_create_objects_in_root')) {
         $member_where_conditions = "member_id=0 OR ";
         $dim_where_conditions = " OR d.id IS NULL";
     }
     $sql_where = "({$member_where_conditions} member_id IN ( SELECT member_id FROM " . $table_prefix . "object_members WHERE object_id = {$oid} AND is_optimization = 0)) AND cmp.object_type_id = {$tid}";
     //3. If there are dimensions that defines permissions containing any of the object members
     if (count($dids)) {
         // 3.1 get permission groups with permissions over the object.
         $sql_fields = "permission_group_id  AS group_id";
         $sql = "\r\n\t\t\t\tSELECT\r\n\t\t\t\t{$sql_fields}\r\n\t\t\t\tFROM\r\n\t\t\t\t{$sql_from}\r\n\t\t\t\tWHERE\r\n\t\t\t\t{$sql_where} AND (d.id IN (" . implode(',', $dids) . ") {$dim_where_conditions})\r\n\t\t\t";
         $res = DB::execute($sql);
         $gids_tmp = array();
         while ($row = $res->fetchRow()) {
             $gids_tmp[$row['group_id']] = $row['group_id'];
         }
         $res->free();
         // allow all permission groups
         $allow_all_rows = DB::executeAll("SELECT DISTINCT permission_group_id FROM " . $table_prefix . "contact_dimension_permissions cdp\r\n\t\t\t\t\tINNER JOIN " . $table_prefix . "members m on m.dimension_id=cdp.dimension_id\r\n\t\t\t\t\tWHERE cdp.permission_type='allow all' AND cdp.dimension_id IN (" . implode(',', $dids) . ");");
         if (is_array($allow_all_rows)) {
             foreach ($allow_all_rows as $row) {
                 $gids_tmp[$row['permission_group_id']] = $row['permission_group_id'];
             }
         }
         $gids = array_values($gids_tmp);
         $gids_tmp = null;
         // check for mandatory dimensions
         $enabled_dimensions_sql = "";
         $enabled_dimensions_ids = implode(',', config_option('enabled_dimensions'));
         if ($enabled_dimensions_ids != "") {
             $enabled_dimensions_sql = "AND id IN ({$enabled_dimensions_ids})";
         }
         $mandatory_dim_ids = Dimensions::findAll(array('id' => true, 'conditions' => "`defines_permissions`=1 {$enabled_dimensions_sql} AND `permission_query_method`='" . DIMENSION_PERMISSION_QUERY_METHOD_MANDATORY . "'"));
         if (count($gids) > 0 && count($mandatory_dim_ids) > 0) {
             $sql = "SELECT om.member_id, m.dimension_id FROM " . $table_prefix . "object_members om\r\n\t\t\t\t\tINNER JOIN " . $table_prefix . "members m ON m.id=om.member_id INNER JOIN " . $table_prefix . "dimensions d ON d.id=m.dimension_id\r\n\t\t\t\t\tWHERE om.object_id = {$oid} AND om.is_optimization = 0 AND d.id IN (" . implode(",", $mandatory_dim_ids) . ")";
             // Object members in mandatory dimensions
             $object_member_ids_res = DB::executeAll($sql);
             $mandatory_dim_members = array();
             if (!is_null($object_member_ids_res)) {
                 foreach ($object_member_ids_res as $row) {
                     if (!isset($mandatory_dim_members[$row['dimension_id']])) {
                         $mandatory_dim_members[$row['dimension_id']] = array();
                     }
                     $mandatory_dim_members[$row['dimension_id']][] = $row['member_id'];
                 }
                 $mandatory_dim_allowed_pgs = array();
                 // Check foreach group that it has permissions over at least one member of each mandatory dimension
                 foreach ($mandatory_dim_members as $mdim_id => $mmember_ids) {
                     $sql = "SELECT pg.id FROM " . $table_prefix . "permission_groups pg\r\n\t\t\t\t\t\t\tINNER JOIN " . $table_prefix . "contact_dimension_permissions cdp ON cdp.permission_group_id=pg.id\r\n\t\t\t\t\t\t\tINNER JOIN " . $table_prefix . "contact_member_permissions cmp ON cmp.permission_group_id=pg.id\r\n\t\t\t\t\t\t\tWHERE cdp.dimension_id = '{$mdim_id}' AND (\r\n\t\t\t\t\t\t\tcdp.permission_type='allow all' OR cdp.permission_type='check' AND cmp.permission_group_id IN (" . implode(',', $gids) . ")\r\n\t\t\t\t\t\t\tAND cmp.member_id IN (" . implode(',', $mmember_ids) . ")\r\n\t\t\t\t\t\t)";
                     $permission_groups_res = DB::executeAll($sql);
                     $mandatory_dim_allowed_pgs[$mdim_id] = array();
                     if (!is_null($permission_groups_res)) {
                         foreach ($permission_groups_res as $row) {
                             if (!in_array($row['id'], $mandatory_dim_allowed_pgs[$mdim_id])) {
                                 $mandatory_dim_allowed_pgs[$mdim_id][] = $row['id'];
                             }
                         }
                     }
                 }
                 if (isset($mandatory_dim_allowed_pgs) && count($mandatory_dim_allowed_pgs) > 0) {
                     $original_mandatory_dim_allowed_pgs = $mandatory_dim_allowed_pgs;
                     $allowed_gids = array_pop($mandatory_dim_allowed_pgs);
                     foreach ($mandatory_dim_allowed_pgs as $pg_array) {
                         $allowed_gids = array_intersect($allowed_gids, $pg_array);
                     }
                     // If an user has permissions in one dim using a group and in other dim using his personal permissions then add to sharing table its personal permission group
                     $pg_ids = array_unique(array_flat($original_mandatory_dim_allowed_pgs));
                     if (count($pg_ids) == 0) {
                         $pg_ids[0] = 0;
                     }
                     $contact_pgs = array();
                     $contact_pg_rows = DB::executeAll("SELECT * FROM " . TABLE_PREFIX . "contact_permission_groups WHERE permission_group_id IN (" . implode(',', $pg_ids) . ") ORDER BY permission_group_id");
                     if (is_array($contact_pg_rows)) {
                         foreach ($contact_pg_rows as $cpgr) {
                             if (!isset($contact_pgs[$cpgr['contact_id']])) {
                                 $contact_pgs[$cpgr['contact_id']] = array();
                             }
                             $contact_pgs[$cpgr['contact_id']][] = $cpgr['permission_group_id'];
                         }
                     }
                     // each user must have at least one pg for every dimension
                     foreach ($contact_pgs as $contact_id => $permission_groups) {
                         $has_one = array_flip(array_keys($original_mandatory_dim_allowed_pgs));
                         foreach ($has_one as $k => &$v) {
                             $v = false;
                         }
                         foreach ($permission_groups as $pg_id) {
                             foreach ($original_mandatory_dim_allowed_pgs as $dim_id => $allowedpgs) {
                                 if (in_array($pg_id, $allowedpgs)) {
                                     $has_one[$dim_id] = true;
                                     break;
                                 }
                             }
                         }
                         // all dims must be true in this array to allow permissions
                         $has_permission = !in_array(false, $has_one);
                         if ($has_permission) {
                             $contact_row = DB::executeOne("SELECT permission_group_id FROM " . TABLE_PREFIX . "contacts where object_id = {$contact_id}");
                             if (is_array($contact_row) && $contact_row['permission_group_id'] > 0) {
                                 $allowed_gids[] = $contact_row['permission_group_id'];
                             }
                         }
                     }
                     $gids = array_unique($allowed_gids, SORT_NUMERIC);
                 } else {
                     $gids = array();
                 }
             }
         }
     } else {
         if ($obj_mem_ids) {
             // 3.2 No memeber dimensions defines permissions.
             // No esta en ninguna dimension que defina permisos, El objecto esta en algun lado
             // => En todas las dimensiones en la que está no definen permisos => Busco todos los grupos
             $gids = PermissionGroups::instance()->findAll(array('id' => true, 'conditions' => "type != 'roles'"));
         } else {
             // if this object is an email and it is unclassified => add to sharing table the permission groups of the users that have permissions in the email's account
             if (Plugins::instance()->isActivePlugin('mail')) {
                 $mail_ot = ObjectTypes::instance()->findByName('mail');
                 if ($mail_ot instanceof ObjectType && $tid == $mail_ot->getId()) {
                     $gids = array_flat(DB::executeAll("\r\n\t\t\t\t\t\t\tSELECT cpg.permission_group_id\r\n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "contact_permission_groups cpg\r\n\t\t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "contacts c ON c.permission_group_id=cpg.permission_group_id\r\n\t\t\t\t\t\t\tWHERE cpg.contact_id IN (\r\n\t\t\t\t\t\t\t  SELECT mac.contact_id FROM " . TABLE_PREFIX . "mail_account_contacts mac WHERE mac.account_id = (SELECT mc.account_id FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id={$oid})\r\n\t\t\t\t\t\t\t);\r\n\t\t\t\t\t\t"));
                 }
             }
         }
     }
     if (count($gids)) {
         $stManager = SharingTables::instance();
         $stManager->populateGroups($gids, $oid);
         $gids = null;
     }
 }
 function dimension_tree_for_permissions()
 {
     $dimension_id = array_var($_REQUEST, 'dimension_id');
     $checkedField = array_var($_REQUEST, 'checkboxes') ? "checked" : "_checked";
     $objectTypeId = array_var($_REQUEST, 'object_type_id', null);
     $allowedMemberTypes = json_decode(array_var($_REQUEST, 'allowedMemberTypes', null));
     if (!is_array($allowedMemberTypes)) {
         $allowedMemberTypes = null;
     }
     $only_names = array_var($_REQUEST, 'onlyname', false);
     $name = trim(array_var($_REQUEST, 'query', ''));
     $extra_cond = $name == "" ? "" : " AND name LIKE '%" . $name . "%'";
     if (array_var($_REQUEST, 'new_user')) {
         if (isset($_REQUEST['forced_members'])) {
             $forced_members = json_decode(array_var($_REQUEST, 'forced_members', ''));
             $fms = array(0);
             if (is_array($forced_members) && count($forced_members) > 0) {
                 foreach ($forced_members as $fm) {
                     if (is_numeric($fm)) {
                         $fms[] = $fm;
                     }
                 }
             }
             if (count($fms) > 0) {
                 $extra_cond .= " AND id IN (" . implode(',', $fms) . ")";
             }
         }
         if (isset($_REQUEST['excluded_members'])) {
             $excluded_members = json_decode(array_var($_REQUEST, 'excluded_members', ''));
             $ems = array(0);
             if (is_array($excluded_members) && count($excluded_members) > 0) {
                 foreach ($excluded_members as $em) {
                     if (is_numeric($em)) {
                         $ems[] = $em;
                     }
                 }
             }
             if (count($ems) > 0) {
                 $extra_cond .= " AND id NOT IN (" . implode(',', $ems) . ")";
             }
         }
     } else {
         // only use available object types
         $ots = ObjectTypes::getAvailableObjectTypes();
         $available_ots_csv = "";
         foreach ($ots as $ot) {
             $available_ots_csv .= ($available_ots_csv == "" ? "" : ",") . $ot->getId();
         }
         if (trim($available_ots_csv) != "") {
             $ot_cond = " AND cmp.object_type_id IN ({$available_ots_csv})";
         } else {
             $ot_cond = "";
         }
         if (array_var($_REQUEST, 'only_with_perm')) {
             $extra_cond .= " AND EXISTS (SELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=id AND cmp.permission_group_id=" . array_var($_REQUEST, 'pg', '-1') . " {$ot_cond})";
         } else {
             if (array_var($_REQUEST, 'only_without_perm')) {
                 $extra_cond .= " AND NOT EXISTS (SELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=id AND cmp.permission_group_id=" . array_var($_REQUEST, 'pg', '-1') . " {$ot_cond})";
             }
         }
     }
     $return_all_members = false;
     $selected_member_ids = json_decode(array_var($_REQUEST, 'selected_ids', "[0]"));
     $selected_members = Members::findAll(array('conditions' => 'id IN (' . implode(',', $selected_member_ids) . ')'));
     $memberList = $this->initial_list_dimension_members($dimension_id, $objectTypeId, $allowedMemberTypes, $return_all_members, $extra_cond, null, false, null, $only_names, $selected_members);
     // add missing parents
     $missing_parent_ids = array();
     $all_members = array();
     foreach ($memberList as $m) {
         $all_members[$m['id']] = $m['id'];
     }
     foreach ($memberList as $m) {
         if ($m['parent'] > 0 && !isset($all_members[$m['parent']])) {
             $missing_parent_ids[$m['parent']] = $m['parent'];
         }
     }
     while (count($missing_parent_ids) > 0) {
         $missing_members = DB::executeAll("SELECT m.*, ot.icon FROM " . TABLE_PREFIX . "members m INNER JOIN " . TABLE_PREFIX . "object_types ot ON ot.id=m.object_type_id WHERE m.id IN (" . implode(',', $missing_parent_ids) . ")");
         $missing_parent_ids = array();
         $new_missing = array();
         foreach ($missing_members as $mem) {
             $m = array("id" => $mem['id'], "name" => clean($mem['name']), "parent" => $mem['parent_member_id'], "realParent" => $mem['parent_member_id'], "object_id" => $mem['object_id'], "depth" => $mem['depth'], "iconCls" => 'ico-' . $mem['icon'], "dimension_id" => $mem['dimension_id'], "object_type_id" => $mem['object_type_id'], "expandable" => true);
             $memberList[str_pad(array_var($m, 'parent'), 20, "0", STR_PAD_LEFT) . strtolower(array_var($m, 'name')) . array_var($m, 'id')] = $m;
             $new_missing[] = $m;
             $all_members[$m['id']] = $m;
         }
         foreach ($new_missing as $m) {
             if ($m['parent'] > 0 && !isset($all_members[$m['parent']])) {
                 $missing_parent_ids[$m['parent']] = $m['parent'];
             }
         }
     }
     // --
     $tree = buildTree($memberList, "parent", "children", "id", "name", $checkedField);
     ajx_current("empty");
     ajx_extra_data(array('dimension_members' => $tree, 'dimension_id' => $dimension_id));
 }
Пример #18
0
function core_dimensions_update_9_10()
{
    $template_ot = ObjectTypes::findByName('template');
    $users = Contacts::getAllUsers();
    foreach ($users as $user) {
        /* @var $user Contact */
        if (!$user->isAdminGroup()) {
            continue;
        }
        // don't allow to write emails for collaborators and guests
        $user_type_name = $user->getUserTypeName();
        if ($template_ot instanceof ObjectType) {
            DB::executeAll("UPDATE " . TABLE_PREFIX . "contact_member_permissions SET can_write=1, can_delete=1 WHERE object_type_id=" . $template_ot->getId() . " AND permission_group_id=" . $user->getPermissionGroupId());
        }
    }
    $pgs = PermissionGroups::findAll(array("conditions" => "`name` in ('Super Administrator','Administrator')"));
    foreach ($pgs as $pg) {
        DB::executeAll("UPDATE " . TABLE_PREFIX . "role_object_type_permissions SET can_write=1, can_delete=1 WHERE object_type_id=" . $template_ot->getId() . " AND role_id=" . $user->getPermissionGroupId());
    }
}
Пример #19
0
    $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());
                }
            }
        }
Пример #20
0
 static function prepareFiltersConditions($filters)
 {
     $name_filter_condition = "";
     $obj_ids_filter_condition = "";
     $type_filter_condition = "";
     if (!is_null($filters) && is_array($filters)) {
         $type_filters = array_var($filters, 'types');
         if (is_array($type_filters) && count($type_filters) > 0) {
             $type_filters_ids = ObjectTypes::findAll(array('id' => 'true', 'conditions' => "`name` IN (" . DB::escape($type_filters) . ")"));
             $type_filter_condition = " AND `o`.`object_type_id` IN (" . implode(",", $type_filters_ids) . ")";
         }
         $name_filter = array_var($filters, 'name');
         $name_filter_condition = is_null($name_filter) ? "" : " AND `o`.`name` LIKE " . DB::escape("{$name_filter}%");
         $obj_ids_filter = array_var($filters, 'object_ids');
         $obj_ids_filter_condition = is_null($obj_ids_filter) ? "" : " AND `o`.`id` IN ({$obj_ids_filter})";
     }
     return array($name_filter_condition, $obj_ids_filter_condition, $type_filter_condition);
 }
Пример #21
0
<?php

$genid = gen_id();
$selectedPage = user_config_option('custom_report_tab');
$customReports = Reports::getAllReportsByObjectType();
$report = new Report();
$can_add_reports = $report->canAdd(logged_user(), active_context());
$reportPages = array();
$object_types = ObjectTypes::getAvailableObjectTypes();
foreach ($object_types as $ot) {
    $reportPages[$ot->getId()] = array("name" => $ot->getName(), "display_name" => lang($ot->getName()));
}
$ignored = null;
Hook::fire('modify_report_pages', $ignored, $reportPages);
// To add, edit or remove report pages
$default_reports = array('task' => array('task time report' => array('url' => get_url('reporting', 'total_task_times_p'), 'name' => lang('task time report'), 'description' => lang('task time report description'))));
Hook::fire('modify_default_reports', $ignored, $default_reports);
// To add, edit or remove default reports
require_javascript("og/ReportingFunctions.js");
?>

<div style="padding:7px">
<table width=100% id="reportingMenu">
<tr>
	<td style="height:2px;width:140px"></td><td width=12></td><td style="line-height:2px;">&nbsp;</td><td width=12></td>
</tr>
<tr>
<td height=12></td>
<td rowspan=<?php 
echo count($reportPages) + 2;
?>
Пример #22
0
        echo $type->getIcon();
        ?>
'
			});
<?php 
    }
}
?>
	var searchForm = document.getElementById("searchbox").getElementsByTagName("form")[0] ;
	H5F.setup(searchForm);


	og.additional_on_dimension_object_click = [];
	og.dimension_object_types = [];
<?php 
$dimension_object_types = ObjectTypes::findAll(array('conditions' => "`type` IN ('dimension_object', 'dimension_group')"));
foreach ($dimension_object_types as $dot) {
    ?>
		og.dimension_object_types[<?php 
    echo $dot->getId();
    ?>
] = '<?php 
    echo $dot->getName();
    ?>
';
<?php 
}
foreach (Plugins::instance()->getActive() as $p) {
    $js_code = 'if (og.' . $p->getName() . ' && og.' . $p->getName() . '.init) og.' . $p->getName() . '.init();' . "\n";
    echo $js_code;
}
Пример #23
0
 /**
  * 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() . '">&nbsp;</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;
 }
	</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;
Пример #25
0
    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 
 /**
  * List custom properties
  *
  * @access public
  * @param void
  * @return null
  */
 function custom_properties()
 {
     if (!can_manage_configuration(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $object_types = ObjectTypes::instance()->findAll(array("conditions" => "`type` = 'content_object' AND `name` <> 'file revision'", "order" => "name"));
     $ordered_object_types = array();
     foreach ($object_types as $ot) {
         $ordered_object_types[$ot->getId()] = lang($ot->getName());
     }
     asort($ordered_object_types, SORT_STRING);
     $select_options = array('<option value="" selected>' . lang('select one') . '</option>');
     foreach ($ordered_object_types as $k => $v) {
         $select_options[] = '<option value="' . $k . '">' . $v . '</option>';
     }
     tpl_assign('object_types', $select_options);
     $custom_properties = array_var($_POST, 'custom_properties');
     $obj_type_id = array_var($_POST, 'objectType');
     if (is_array($custom_properties)) {
         try {
             DB::beginWork();
             foreach ($custom_properties as $id => $data) {
                 $new_cp = null;
                 if ($data['id'] != '') {
                     $new_cp = CustomProperties::getCustomProperty($data['id']);
                 }
                 if ($new_cp == null) {
                     $new_cp = new CustomProperty();
                 }
                 if ($data['deleted'] == "1") {
                     $new_cp->delete();
                     continue;
                 }
                 $new_cp->setObjectTypeId($obj_type_id);
                 $new_cp->setName($data['name']);
                 $new_cp->setType($data['type']);
                 $new_cp->setDescription($data['description']);
                 if ($data['type'] == 'list') {
                     $values = array();
                     $list = explode(",", $data['values']);
                     foreach ($list as $l) {
                         $values[] = trim($l);
                     }
                     $value = implode(",", $values);
                     $new_cp->setValues($value);
                 } else {
                     $new_cp->setValues($data['values']);
                 }
                 if ($data['type'] == 'boolean') {
                     $new_cp->setDefaultValue(isset($data['default_value_boolean']));
                 } else {
                     $new_cp->setDefaultValue($data['default_value']);
                 }
                 $new_cp->setIsRequired(isset($data['required']));
                 $new_cp->setIsMultipleValues(isset($data['multiple_values']));
                 $new_cp->setOrder($id);
                 $new_cp->setVisibleByDefault(isset($data['visible_by_default']));
                 $new_cp->save();
                 if (is_array(array_var($data, 'applyto'))) {
                     $applyto = array_var($data, 'applyto');
                     foreach ($applyto as $co_type => $value) {
                         if ($value == 'true') {
                             if (!CustomPropertiesByCoType::findById(array('co_type_id' => $co_type, 'cp_id' => $new_cp->getId()))) {
                                 $obj = new CustomPropertyByCoType();
                                 $obj->setCoTypeId($co_type);
                                 $obj->setCpId($new_cp->getId());
                                 $obj->save();
                             }
                         } else {
                             $obj = CustomPropertiesByCoType::findById(array('co_type_id' => $co_type, 'cp_id' => $new_cp->getId()));
                             if ($obj) {
                                 $obj->delete();
                             }
                         }
                     }
                 }
             }
             DB::commit();
             flash_success(lang('custom properties updated'));
             ajx_current('back');
         } catch (Exception $ex) {
             DB::rollback();
             flash_error($ex->getMessage());
         }
     }
 }
Пример #27
0
	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");
		}
	}
Пример #28
0
 function list_objects()
 {
     //alert("debugging. remove this line");ajx_current('empty'); return array() ; //TODO remove this line
     /* get query parameters */
     $filesPerPage = config_option('files_per_page');
     $start = array_var($_GET, 'start') ? (int) array_var($_GET, 'start') : 0;
     $limit = array_var($_GET, 'limit') ? array_var($_GET, 'limit') : $filesPerPage;
     $order = array_var($_GET, 'sort');
     $ignore_context = (bool) array_var($_GET, 'ignore_context');
     if ($order == "dateUpdated") {
         $order = "updated_on";
     } elseif ($order == "dateArchived") {
         $order = "archived_on";
     } elseif ($order == "dateDeleted") {
         $order = "trashed_on";
     }
     $orderdir = array_var($_GET, 'dir');
     $page = (int) ($start / $limit) + 1;
     $hide_private = !logged_user()->isMemberOfOwnerCompany();
     $typeCSV = array_var($_GET, 'type');
     $types = null;
     if ($typeCSV) {
         $types = explode(",", $typeCSV);
     }
     $name_filter = mysql_escape_string(array_var($_GET, 'name'));
     $linked_obj_filter = array_var($_GET, 'linkedobject');
     $object_ids_filter = '';
     if (!is_null($linked_obj_filter)) {
         $linkedObject = Objects::findObject($linked_obj_filter);
         $objs = $linkedObject->getLinkedObjects();
         foreach ($objs as $obj) {
             $object_ids_filter .= ($object_ids_filter == '' ? '' : ',') . $obj->getId();
         }
     }
     $filters = array();
     if (!is_null($types)) {
         $filters['types'] = $types;
     }
     if (!is_null($name_filter)) {
         $filters['name'] = $name_filter;
     }
     if ($object_ids_filter != '') {
         $filters['object_ids'] = $object_ids_filter;
     }
     $user = array_var($_GET, 'user');
     $trashed = array_var($_GET, 'trashed', false);
     $archived = array_var($_GET, 'archived', false);
     /* if there's an action to execute, do so */
     if (array_var($_GET, 'action') == 'delete') {
         $ids = explode(',', array_var($_GET, 'objects'));
         $result = ContentDataObjects::listing(array("extra_conditions" => " AND o.id IN (" . implode(",", $ids) . ") ", "include_deleted" => true));
         $objects = $result->objects;
         list($succ, $err) = $this->do_delete_objects($objects);
         if ($err > 0) {
             flash_error(lang('error delete objects', $err));
         } else {
             Hook::fire('after_object_delete_permanently', $ids, $ignored);
             flash_success(lang('success delete objects', $succ));
         }
     } else {
         if (array_var($_GET, 'action') == 'delete_permanently') {
             $ids = explode(',', array_var($_GET, 'objects'));
             //$result = Objects::getObjectsFromContext(active_context(), null, null, true, false, array('object_ids' => implode(",",$ids)));
             $objects = Objects::instance()->findAll(array("conditions" => "id IN (" . implode(",", $ids) . ")"));
             list($succ, $err) = $this->do_delete_objects($objects, true);
             if ($err > 0) {
                 flash_error(lang('error delete objects', $err));
             }
             if ($succ > 0) {
                 Hook::fire('after_object_delete_permanently', $ids, $ignored);
                 flash_success(lang('success delete objects', $succ));
             }
         } else {
             if (array_var($_GET, 'action') == 'markasread') {
                 $ids = explode(',', array_var($_GET, 'objects'));
                 list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, true);
             } else {
                 if (array_var($_GET, 'action') == 'markasunread') {
                     $ids = explode(',', array_var($_GET, 'objects'));
                     list($succ, $err) = $this->do_mark_as_read_unread_objects($ids, false);
                 } else {
                     if (array_var($_GET, 'action') == 'empty_trash_can') {
                         $result = Objects::getObjectsFromContext(active_context(), 'trashed_on', 'desc', true);
                         $objects = $result->objects;
                         list($succ, $err) = $this->do_delete_objects($objects, true);
                         if ($err > 0) {
                             flash_error(lang('error delete objects', $err));
                         }
                         if ($succ > 0) {
                             flash_success(lang('success delete objects', $succ));
                         }
                     } else {
                         if (array_var($_GET, 'action') == 'archive') {
                             $ids = explode(',', array_var($_GET, 'objects'));
                             list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'archive');
                             if ($err > 0) {
                                 flash_error(lang('error archive objects', $err));
                             } else {
                                 flash_success(lang('success archive objects', $succ));
                             }
                         } else {
                             if (array_var($_GET, 'action') == 'unarchive') {
                                 $ids = explode(',', array_var($_GET, 'objects'));
                                 list($succ, $err) = $this->do_archive_unarchive_objects($ids, 'unarchive');
                                 if ($err > 0) {
                                     flash_error(lang('error unarchive objects', $err));
                                 } else {
                                     flash_success(lang('success unarchive objects', $succ));
                                 }
                             } else {
                                 if (array_var($_GET, 'action') == 'unclassify') {
                                     $ids = explode(',', array_var($_GET, 'objects'));
                                     $err = 0;
                                     $succ = 0;
                                     foreach ($ids as $id) {
                                         $split = explode(":", $id);
                                         $type = $split[0];
                                         if (Plugins::instance()->isActivePlugin('mail') && $type == 'MailContents') {
                                             $email = MailContents::findById($split[1]);
                                             if (isset($email) && !$email->isDeleted() && $email->canEdit(logged_user())) {
                                                 if (MailController::do_unclassify($email)) {
                                                     $succ++;
                                                 } else {
                                                     $err++;
                                                 }
                                             } else {
                                                 $err++;
                                             }
                                         }
                                     }
                                     if ($err > 0) {
                                         flash_error(lang('error unclassify emails', $err));
                                     } else {
                                         flash_success(lang('success unclassify emails', $succ));
                                     }
                                 } else {
                                     if (array_var($_GET, 'action') == 'restore') {
                                         $errorMessage = null;
                                         $ids = explode(',', array_var($_GET, 'objects'));
                                         $success = 0;
                                         $error = 0;
                                         foreach ($ids as $id) {
                                             $obj = Objects::findObject($id);
                                             if ($obj->canDelete(logged_user())) {
                                                 try {
                                                     $obj->untrash($errorMessage);
                                                     if ($obj->getObjectTypeId() == 11) {
                                                         $event = ProjectEvents::findById($obj->getId());
                                                         if ($event->getExtCalId() != "") {
                                                             $this->created_event_google_calendar($obj, $event);
                                                         }
                                                     }
                                                     ApplicationLogs::createLog($obj, ApplicationLogs::ACTION_UNTRASH);
                                                     $success++;
                                                 } catch (Exception $e) {
                                                     $error++;
                                                 }
                                             } else {
                                                 $error++;
                                             }
                                         }
                                         if ($success > 0) {
                                             flash_success(lang("success untrash objects", $success));
                                         }
                                         if ($error > 0) {
                                             $errorString = is_null($errorMessage) ? lang("error untrash objects", $error) : $errorMessage;
                                             flash_error($errorString);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $filterName = array_var($_GET, 'name');
     $result = null;
     $context = active_context();
     $obj_type_types = array('content_object', 'dimension_object');
     if (array_var($_GET, 'include_comments')) {
         $obj_type_types[] = 'comment';
     }
     $type_condition = "";
     if ($types) {
         $type_condition = " AND name IN ('" . implode("','", $types) . "')";
     }
     $res = DB::executeAll("SELECT id from " . TABLE_PREFIX . "object_types WHERE type IN ('" . implode("','", $obj_type_types) . "') AND name <> 'file revision' {$type_condition} ");
     $type_ids = array();
     foreach ($res as $row) {
         if (ObjectTypes::isListableObjectType($row['id'])) {
             $types_ids[] = $row['id'];
         }
     }
     //Hook::fire('list_objects_type_ids', null, $types_ids);
     $type_ids_csv = implode(',', $types_ids);
     $extra_conditions = array();
     $extra_conditions[] = "object_type_id in ({$type_ids_csv})";
     if ($name_filter) {
         $extra_conditions[] = "name LIKE '%{$name_filter}%'";
     }
     //$pagination = Objects::getObjects($context,$start,$limit,$order,$orderdir,$trashed,$archived, $filters,$start, $limit, $obj_type_types);
     $pagination = ContentDataObjects::listing(array("start" => $start, "limit" => $limit, "order" => $order, "order_dir" => $orderdir, "trashed" => $trashed, "archived" => $archived, "types" => $types, "count_results" => false, "extra_conditions" => " AND " . implode(" AND ", $extra_conditions), "ignore_context" => $ignore_context));
     $result = $pagination->objects;
     $total_items = $pagination->total;
     if (!$result) {
         $result = array();
     }
     /* prepare response object */
     $info = array();
     foreach ($result as $obj) {
         $info_elem = $obj->getArrayInfo($trashed, $archived);
         $instance = Objects::instance()->findObject($info_elem['object_id']);
         $info_elem['url'] = $instance->getViewUrl();
         /* @var $instance Contact  */
         if ($instance instanceof Contact) {
             if ($instance->isCompany()) {
                 $info_elem['icon'] = 'ico-company';
                 $info_elem['type'] = 'company';
             }
         } else {
             if ($instance instanceof ProjectFile) {
                 $info_elem['mimeType'] = $instance->getTypeString();
             }
         }
         $info_elem['isRead'] = $instance->getIsRead(logged_user()->getId());
         $info_elem['manager'] = get_class($instance->manager());
         $info_elem['memPath'] = json_encode($instance->getMembersToDisplayPath());
         $info[] = $info_elem;
     }
     $listing = array("totalCount" => $total_items, "start" => $start, "objects" => $info);
     ajx_extra_data($listing);
     tpl_assign("listing", $listing);
     if (isset($reload) && $reload) {
         ajx_current("reload");
     } else {
         ajx_current("empty");
     }
 }
Пример #29
0
        }
    }
}
if ($show_widget) {
    $extra_conditions = " AND parent_member_id " . ($add_ctx_members && count($allowed_members) > 0 ? "IN (" . implode(",", $allowed_members) . ")" : "=0");
    $parent = null;
    $context = active_context();
    if (is_array($context)) {
        foreach ($context as $selection) {
            if ($selection instanceof Member && $selection->getDimensionId() == $ws_dimension->getId()) {
                $parent = $selection;
                break;
            }
        }
    }
    $ws_ot_id = ObjectTypes::findByName('workspace')->getId();
    $pg_array = logged_user()->getPermissionGroupIds();
    $current_member_cond = $parent instanceof Member ? "AND parent_member_id=" . $parent->getId() : "";
    $members = Members::findAll(array('limit' => $limit, 'order' => "depth, name", 'conditions' => "object_type_id={$ws_ot_id} {$current_member_cond} AND archived_by_id=0 AND EXISTS (\r\n\t\t\tSELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.permission_group_id IN (" . implode(',', $pg_array) . "))"));
    if ($parent instanceof Member && count($members) < $limit) {
        $tmp_ids = array();
        foreach ($members as $m) {
            $tmp_ids[] = $m->getId();
        }
        $extra_conds = "AND archived_by_id=0 AND EXISTS (\r\n\t\t\tSELECT cmp.member_id FROM " . TABLE_PREFIX . "contact_member_permissions cmp WHERE cmp.member_id=" . TABLE_PREFIX . "members.id AND cmp.permission_group_id IN (" . implode(',', $pg_array) . "))";
        $childs = $parent->getAllChildren(true, 'name', $extra_conds);
        foreach ($childs as $ch) {
            if (in_array($ch->getId(), $tmp_ids)) {
                continue;
            }
            if ($ch->getObjectTypeId() == $ws_ot_id && count($members) <= $limit) {
Пример #30
0
 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;
 }