/** * Empty implementation of abstract methods. Messages determine does user have * permissions to add comment * * @param void * @return null */ function canAdd(User $user, Project $project) { return can_add($user, $project, get_class(ProjectFiles::instance())); }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'ProjectFiles')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return ProjectFiles::instance()->paginate($arguments, $items_per_page, $current_page); } // if }
/** * Return manager instance * * @access protected * @param void * @return ProjectFiles */ function manager() { if (!$this->manager instanceof ProjectFiles) { $this->manager = ProjectFiles::instance(); } return $this->manager; }
function list_files() { ajx_current("empty"); // get query parameters $start = (integer)array_var($_GET,'start'); $limit = (integer)array_var($_GET,'limit'); if (! $start) { $start = 0; } if (! $limit) { $limit = config_option('files_per_page'); } $order = array_var($_GET,'sort'); $order_dir = array_var($_GET,'dir'); $page = (integer) ($start / $limit)+1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $type = array_var($_GET,'type'); $user = array_var($_GET,'user'); // if there's an action to execute, do so if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canDelete(logged_user())) { try{ DB::beginWork(); $file->trash(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success delete files", $succ)); } else { flash_error(lang("error delete files", $err)); } } else if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(),true); $succ++; } catch(Exception $e) { $err ++; } // try }//for if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } }else if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(),false); $succ++; } catch(Exception $e) { $err ++; } // try }//for if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else if (array_var($_GET, 'action') == 'zip_add') { $this->zip_add(); } else if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canEdit(logged_user())) { try{ DB::beginWork(); $file->archive(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE); DB::commit(); $succ++; } catch(Exception $e){ DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } else { flash_error(lang("error archive objects", $err)); } } Hook::fire('classify_action', null, $ret); $join_params = null; if ($order == ProjectFiles::ORDER_BY_POSTTIME) { $order = '`created_on`'; } else if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) { $order = '`updated_on`'; } else if ($order == ProjectFiles::ORDER_BY_SIZE) { $order = '`jt`.`filesize`'; $join_params = array( 'table' => ProjectFileRevisions::instance()->getTableName(), 'jt_field' => 'object_id', 'j_sub_q' => "SELECT max(`x`.`object_id`) FROM ".ProjectFileRevisions::instance()->getTableName()." `x` WHERE `x`.`file_id` = `e`.`object_id`" ); } else { $order = '`name`'; } // if $extra_conditions = $hide_private ? 'AND `is_visible` = 1' : ''; $context = active_context(); $objects = ProjectFiles::instance()->listing(array( "order"=>$order, "order_dir" => $order_dir, "extra_conditions"=> $extra_conditions, "join_params"=> $join_params, "start"=> $start, "limit"=> $limit )); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId()); // prepare response object $listing = array( "totalCount" => $objects->total, "start" => $start, "objType" => ProjectFiles::instance()->getObjectTypeId(), "files" => array(), ); if (is_array($objects->objects)) { $index = 0; $ids = array(); foreach ($objects->objects as $o) { $coName = ""; $coId = $o->getCheckedOutById(); if ($coId != 0) { if ($coId == logged_user()->getId()) { $coName = "self"; } else { $coUser = Contacts::findById($coId); if ($coUser instanceof Contact) { $coName = $coUser->getUsername(); } else { $coName = ""; } } } if ($o->isMP3()) { $songname = $o->getProperty("songname"); $artist = $o->getProperty("songartist"); $album = $o->getProperty("songalbum"); $track = $o->getProperty("songtrack"); $year = $o->getProperty("songyear"); $duration = $o->getProperty("songduration"); $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId())); } else { $songInfo = array(); } $ids[] = $o->getId(); $values = array( "id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "ot_id" => $o->getObjectTypeId(), "name" => $o->getObjectName(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "createdBy" => clean($o->getCreatedByDisplayName()), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? ($o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn())) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => clean($o->getUpdatedByDisplayName()), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? ($o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn())) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => format_filesize($o->getFileSize()), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "memPath" => json_encode($o->getMembersToDisplayPath()), ); if ($o->isMP3()) { $values['isMP3'] = true; } Hook::fire('add_classification_value', $o, $values); foreach ($custom_properties as $cp) { $cp_value = CustomPropertyValues::getCustomPropertyValue($o->getId(), $cp->getId()); $values['cp_'.$cp->getId()] = $cp_value instanceof CustomPropertyValue ? $cp_value->getValue() : ''; } $listing["files"][] = $values; } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach($listing["files"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } ajx_extra_data($listing); tpl_assign("listing", $listing); }else{ throw new Error("Not array", $code); } }
<?php $panel = TabPanels::instance()->findById('documents-panel'); if ($panel instanceof TabPanel && $panel->getEnabled()) { $limit = 5 ; $result = ProjectFiles::instance()->listing(array( "order" => "name", "order_dir" => "asc", "start" => 0, "limit" => $limit )) ; $active_members = array(); $context = active_context(); foreach ($context as $selection) { if ($selection instanceof Member) $active_members[] = $selection; } if (count($active_members) > 0) { $mnames = array(); $allowed_contact_ids = array(); foreach ($active_members as $member) { $mnames[] = clean($member->getName()); } $widget_title = lang('documents'). ' '. lang('in').' '. implode(", ", $mnames); } $total = $result->total ; $documents = $result->objects; $genid = gen_id(); if ($total) { include_once 'template.php'; }
/** * Enter description here... * assumes manager has one field as PK * * @param DataManager $manager * @param $access_level ACCESS_LEVEL_XX objects that defines which permission is being checked * @param string $project_id string that will be compared to the project id while searching project_user table * @param int $user_id user whose permissions are being checked * @return unknown */ function permissions_sql_for_listings(DataManager $manager, $access_level, User $user, $project_id = '`project_id`', $table_alias = null) { if (!$manager instanceof DataManager) { throw new Exception("Invalid manager '{$manager}' in permissions helper", -1); return ''; } $user_id = $user->getId(); $oup_tablename = ObjectUserPermissions::instance()->getTableName(true); $wo_tablename = WorkspaceObjects::instance()->getTableName(true); $users_table_name = Users::instance()->getTableName(true); $pu_table_name = ProjectUsers::instance()->getTableName(true); if ($user->isGuest() && $access_level == ACCESS_LEVEL_WRITE) { return 'false'; } if (isset($table_alias) && $table_alias && $table_alias != '') { $object_table_name = $table_alias; } else { $object_table_name = $manager->getTableName(); } if (!is_numeric($project_id)) { $project_id = "{$object_table_name}.{$project_id}"; } $object_id_field = $manager->getPkColumns(); $object_id = $object_table_name . '.' . $object_id_field; $object_manager = get_class($manager); $access_level_text = access_level_field_name($access_level); $item_class = $manager->getItemClass(); $is_project_data_object = new $item_class() instanceof ProjectDataObject; // permissions for contacts if ($manager instanceof Contacts && can_manage_contacts($user)) { return 'true'; } if ($manager instanceof Companies && can_manage_contacts($user)) { return 'true'; } // permissions for file revisions if ($manager instanceof ProjectFileRevisions) { $pfTableName = "`" . TABLE_PREFIX . "project_files`"; return "{$object_table_name}.`file_id` IN (SELECT `id` FROM {$pfTableName} WHERE " . permissions_sql_for_listings(ProjectFiles::instance(), $access_level, $user) . ")"; } // permissions for projects if ($manager instanceof Projects) { $pcTableName = "`" . TABLE_PREFIX . 'project_users`'; return "{$object_table_name}.`id` IN (SELECT `project_id` FROM {$pcTableName} `pc` WHERE `user_id` = {$user_id})"; } // permissions for users if ($manager instanceof Users) { if (logged_user()->isMemberOfOwnerCompany()) { return "true"; } else { return "{$object_table_name}.`company_id` = " . owner_company()->getId() . " OR {$object_table_name}.`company_id` = " . logged_user()->getCompanyId(); } } $can_manage_object = manager_class_field_name($object_manager, $access_level); // user is creator $str = " ( `created_by_id` = {$user_id}) "; // element belongs to personal project /*if($is_project_data_object) // TODO: type of element belongs to a project if (!in_array('project_id', $manager->getColumns())) { $str .= "\n OR ( EXISTS(SELECT * FROM $users_table_name `xx_u`, $wo_tablename `xx_wo` WHERE `xx_u`.`id` = $user_id AND `xx_u`.`personal_project_id` = `xx_wo`.`workspace_id` AND `xx_wo`.`object_id` = $object_id AND `xx_wo`.`object_manager` = '$object_manager' )) "; } else { $str .= "\n OR ( $project_id = (SELECT `personal_project_id` FROM $users_table_name `xx_u` WHERE `xx_u`.`id` = $user_id)) "; } */ // user or group has specific permissions over object $group_ids = $user->getGroupsCSV(); $all_ids = '(' . $user_id . ($group_ids != '' ? ',' . $group_ids : '') . ')'; $str .= "\n OR ( EXISTS ( SELECT * FROM {$oup_tablename} `xx_oup` \n\t\t\t\tWHERE `xx_oup`.`rel_object_id` = {$object_id} \n\t\t\t\t\tAND `xx_oup`.`rel_object_manager` = '{$object_manager}' \n\t\t\t\t\tAND `xx_oup`.`user_id` IN {$all_ids} \n\t\t\t\t\tAND `xx_oup`.{$access_level_text} = true) )"; if ($is_project_data_object) { // TODO: type of element belongs to a project if (!in_array('project_id', $manager->getColumns())) { $str .= "\n OR ( EXISTS ( SELECT * FROM {$pu_table_name} `xx_pu`, {$wo_tablename} `xx_wo` \n\t\t\t\tWHERE `xx_pu`.`user_id` IN {$all_ids} \n\t\t\t\t\tAND `xx_pu`.`project_id` = `xx_wo`.`workspace_id`\n\t\t\t\t\tAND `xx_wo`.`object_id` = {$object_id} \n\t\t\t\t\tAND `xx_wo`.`object_manager` = '{$object_manager}'\n\t\t\t\t\tAND `xx_pu`.{$can_manage_object} = true ) ) "; } else { $str .= "\n OR ( EXISTS ( SELECT * FROM {$pu_table_name} `xx_pu` \n\t\t\t\tWHERE `xx_pu`.`user_id` IN {$all_ids} \n\t\t\t\t\tAND `xx_pu`.`project_id` = {$project_id} \n\t\t\t\t\tAND `xx_pu`.{$can_manage_object} = true ) ) "; } } // check account permissions in case of emails if ($manager instanceof MailContents) { $maccTableName = MailAccountUsers::instance()->getTableName(true); $str .= "\n OR EXISTS(SELECT `id` FROM {$maccTableName} WHERE `account_id` = {$object_table_name}.`account_id` AND `user_id` = {$user_id})"; if (user_config_option('view deleted accounts emails', null, $user_id)) { $str .= "\n OR ((SELECT count(*) FROM `" . TABLE_PREFIX . "mail_accounts` WHERE `id` = {$object_table_name}.`account_id`) = 0) AND `created_by_id` = {$user_id}"; } } $hookargs = array('manager' => $manager, 'access_level' => $access_level, 'user' => $user, 'project_id' => $project_id, 'table_alias' => $table_alias); Hook::fire('permissions_sql', $hookargs, $str); return ' (' . $str . ') '; }
function slideshow() { $this->setLayout('slideshow'); $fileid = array_var($_GET, 'fileId'); $file = ProjectFiles::instance()->findById($fileid); if (!$file->canView(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $content = $error = null; if (!$file) { $error = 'File not found'; } else { if (strcmp($file->getTypeString(), 'prsn') != 0) { $error = 'File is not a presentation'; } else { $content = remove_css_and_scripts($file->getFileContent()); } } tpl_assign('error', $error); tpl_assign('content', $content); }
function canAdd(Contact $user, $context, &$notAllowedMember = '') { return can_add($user, $context, ProjectFiles::instance()->getObjectTypeId(), $notAllowedMember); }
function list_files() { ajx_current("empty"); // get query parameters $start = (int) array_var($_GET, 'start'); $limit = (int) array_var($_GET, 'limit'); if (!$start) { $start = 0; } if (!$limit) { $limit = config_option('files_per_page'); } $order = array_var($_GET, 'sort'); $order_dir = array_var($_GET, 'dir'); $page = (int) ($start / $limit) + 1; $hide_private = !logged_user()->isMemberOfOwnerCompany(); $type = array_var($_GET, 'type'); $user = array_var($_GET, 'user'); // if there's an action to execute, do so if (array_var($_GET, 'action') == 'delete') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canDelete(logged_user())) { try { DB::beginWork(); $file->trash(); DB::commit(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_TRASH); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { if (!$file instanceof ProjectFile) { evt_add("popup", array('title' => lang('error'), 'message' => lang("file dnx"))); } else { if (!$file->canDelete(logged_user())) { evt_add("popup", array('title' => lang('error'), 'message' => lang("cannot delete file", $file->getObjectName()))); } } $err++; } } if ($succ > 0) { flash_success(lang("success delete files", $succ)); } else { flash_error(lang("error delete files", $err)); } } else { if (array_var($_GET, 'action') == 'markasread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(), true); $succ++; } catch (Exception $e) { $err++; } // try } //for if ($succ <= 0) { flash_error(lang("error markasread files", $err)); } } else { if (array_var($_GET, 'action') == 'markasunread') { $ids = explode(',', array_var($_GET, 'objects')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); try { $file->setIsRead(logged_user()->getId(), false); $succ++; } catch (Exception $e) { $err++; } // try } //for if ($succ <= 0) { flash_error(lang("error markasunread files", $err)); } } else { if (array_var($_GET, 'action') == 'zip_add') { $this->zip_add(); } else { if (array_var($_GET, 'action') == 'archive') { $ids = explode(',', array_var($_GET, 'ids')); $succ = 0; $err = 0; foreach ($ids as $id) { $file = ProjectFiles::findById($id); if (isset($file) && $file->canEdit(logged_user())) { try { DB::beginWork(); $file->archive(); DB::commit(); ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ARCHIVE); $succ++; } catch (Exception $e) { DB::rollback(); $err++; } } else { $err++; } } if ($succ > 0) { flash_success(lang("success archive objects", $succ)); } else { flash_error(lang("error archive objects", $err)); } } } } } } Hook::fire('classify_action', null, $ret); $join_params = null; $select_columns = null; $extra_conditions = ""; if (strpos($order, 'p_') == 1) { $cpId = substr($order, 3); $order = 'customProp'; } if ($order == ProjectFiles::ORDER_BY_POSTTIME) { $order = '`created_on`'; } else { if ($order == ProjectFiles::ORDER_BY_MODIFYTIME) { $order = '`updated_on`'; } else { if ($order == ProjectFiles::ORDER_BY_SIZE) { $order = '`jt`.`filesize`'; $join_params = array('table' => ProjectFileRevisions::instance()->getTableName(), 'jt_field' => 'file_id', 'e_field' => 'object_id'); $extra_conditions .= " AND `jt`.`object_id` = (SELECT max(`x`.`object_id`) FROM " . TABLE_PREFIX . "project_file_revisions `x` WHERE `x`.`file_id` = `e`.`object_id`)"; } else { if ($order == 'customProp') { $order = 'IF(ISNULL(jt.value),1,0),jt.value'; $join_params['join_type'] = "LEFT "; $join_params['table'] = "" . TABLE_PREFIX . "custom_property_values"; $join_params['jt_field'] = "object_id"; $join_params['e_field'] = "object_id"; $join_params['on_extra'] = "AND custom_property_id = " . $cpId; $extra_conditions .= " AND ( custom_property_id = " . $cpId . " OR custom_property_id IS NULL)"; $select_columns = array("DISTINCT o.*", "e.*"); } else { $order = '`name`'; } } } } // if $extra_conditions .= $hide_private ? 'AND `is_visible` = 1' : ''; // filter attachments of other people if not filtering $tmp_mids = array(); foreach (active_context() as $selection) { if ($selection instanceof Member) { $d = $selection->getDimension(); if ($d instanceof Dimension && $d->getIsManageable()) { $tmp_mids[] = $selection->getId(); } } } if (count($tmp_mids) == 0) { if (Plugins::instance()->isActivePlugin('mail')) { $extra_conditions .= " AND IF(e.mail_id=0, true, EXISTS (SELECT mac.contact_id FROM " . TABLE_PREFIX . "mail_account_contacts mac \r\n\t\t\t\t\tWHERE mac.contact_id=o.created_by_id AND mac.account_id=(SELECT mc.account_id FROM " . TABLE_PREFIX . "mail_contents mc WHERE mc.object_id=e.mail_id)))"; } } Hook::fire("listing_extra_conditions", null, $extra_conditions); $only_count_result = array_var($_GET, 'only_result', false); $context = active_context(); $objects = ProjectFiles::instance()->listing(array("order" => $order, "order_dir" => $order_dir, "extra_conditions" => $extra_conditions, "show_only_member_objects" => user_config_option('show_only_member_files'), 'count_results' => false, 'only_count_results' => $only_count_result, "join_params" => $join_params, "start" => $start, "limit" => $limit, "select_columns" => $select_columns)); $custom_properties = CustomProperties::getAllCustomPropertiesByObjectType(ProjectFiles::instance()->getObjectTypeId()); // prepare response object $listing = array("totalCount" => $objects->total, "start" => $start, "objType" => ProjectFiles::instance()->getObjectTypeId(), "files" => array()); if (is_array($objects->objects)) { $index = 0; $ids = array(); foreach ($objects->objects as $o) { $coName = ""; $coId = $o->getCheckedOutById(); if ($coId != 0) { if ($coId == logged_user()->getId()) { $coName = "self"; } else { $coUser = Contacts::findById($coId); if ($coUser instanceof Contact) { $coName = $coUser->getObjectName(); } else { $coName = ""; } } } if ($o->isMP3()) { $songname = $o->getProperty("songname"); $artist = $o->getProperty("songartist"); $album = $o->getProperty("songalbum"); $track = $o->getProperty("songtrack"); $year = $o->getProperty("songyear"); $duration = $o->getProperty("songduration"); $songInfo = json_encode(array($songname, $artist, $album, $track, $year, $duration, $o->getDownloadUrl(), $o->getFilename(), $o->getId())); } else { $songInfo = array(); } $ids[] = $o->getId(); $values = array("id" => $o->getId(), "ix" => $index++, "object_id" => $o->getId(), "ot_id" => $o->getObjectTypeId(), "name" => $o->getObjectName(), "type" => $o->getTypeString(), "mimeType" => $o->getTypeString(), "createdBy" => clean($o->getCreatedByDisplayName()), "createdById" => $o->getCreatedById(), "dateCreated" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() ? format_time($o->getCreatedOn()) : format_datetime($o->getCreatedOn()) : '', "dateCreated_today" => $o->getCreatedOn() instanceof DateTimeValue ? $o->getCreatedOn()->isToday() : 0, "updatedBy" => clean($o->getUpdatedByDisplayName()), "updatedById" => $o->getUpdatedById(), "dateUpdated" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() ? format_time($o->getUpdatedOn()) : format_datetime($o->getUpdatedOn()) : '', "dateUpdated_today" => $o->getUpdatedOn() instanceof DateTimeValue ? $o->getUpdatedOn()->isToday() : 0, "icon" => $o->getTypeIconUrl(), "size" => format_filesize($o->getFileSize()), "url" => $o->getOpenUrl(), "manager" => get_class($o->manager()), "checkedOutByName" => $coName, "checkedOutById" => $coId, "isModifiable" => $o->isModifiable() && $o->canEdit(logged_user()), "modifyUrl" => $o->getModifyUrl(), "songInfo" => $songInfo, "ftype" => $o->getType(), "url" => $o->getUrl(), "memPath" => json_encode($o->getMembersIdsToDisplayPath()), "genid" => gen_id()); if ($o->isMP3()) { $values['isMP3'] = true; } Hook::fire('add_classification_value', $o, $values); foreach ($custom_properties as $cp) { $values['cp_' . $cp->getId()] = get_custom_property_value_for_listing($cp, $o); } $listing["files"][] = $values; } $read_objects = ReadObjects::getReadByObjectList($ids, logged_user()->getId()); foreach ($listing["files"] as &$data) { $data['isRead'] = isset($read_objects[$data['object_id']]); } ajx_extra_data($listing); tpl_assign("listing", $listing); } else { throw new Error("Not array", $code); } }
/** * Returns array of queries that will return Dashboard Objects * * @param string $proj_ids * @param string $tag * @param boolean $count if false the query will return objects, if true it will return object count */ static function getDashboardObjectQueries($project = null, $tag = null, $count = false, $trashed = false, $linkedObject = null, $order = 'updatedOn', $filterName = '', $archived = false, $filterManager = '') { if ($trashed && $trashed !== 'all') { $order = 'trashedOn'; } else { if ($archived) { $order = 'archivedOn'; } } switch ($order) { case 'dateCreated': $order_crit_companies = '`created_on`'; $order_crit_contacts = '`created_on`'; $order_crit_file_revisions = '`created_on`'; $order_crit_calendar = '`created_on`'; $order_crit_tasks = '`created_on`'; $order_crit_milestones = '`created_on`'; $order_crit_webpages = '`created_on`'; $order_crit_files = '`created_on`'; $order_crit_emails = '`received_date`'; $order_crit_comments = '`created_on`'; $order_crit_messages = '`created_on`'; $order_crit_workspaces = '`created_on`'; break; case 'trashedOn': $order_crit_companies = '`trashed_on`'; $order_crit_contacts = '`trashed_on`'; $order_crit_file_revisions = '`trashed_on`'; $order_crit_calendar = '`trashed_on`'; $order_crit_tasks = '`trashed_on`'; $order_crit_milestones = '`trashed_on`'; $order_crit_webpages = '`trashed_on`'; $order_crit_files = '`trashed_on`'; $order_crit_emails = '`trashed_on`'; $order_crit_comments = '`trashed_on`'; $order_crit_messages = '`trashed_on`'; $order_crit_workspaces = '`updated_on`'; break; case 'archivedOn': $order_crit_companies = '`archived_on`'; $order_crit_contacts = '`archived_on`'; $order_crit_file_revisions = '`updated_on`'; $order_crit_calendar = '`archived_on`'; $order_crit_tasks = '`archived_on`'; $order_crit_milestones = '`archived_on`'; $order_crit_webpages = '`archived_on`'; $order_crit_files = '`archived_on`'; $order_crit_emails = '`archived_on`'; $order_crit_comments = '`updated_on`'; $order_crit_messages = '`archived_on`'; $order_crit_workspaces = '`completed_on`'; break; case 'name': $order_crit_companies = '`name`'; $order_crit_contacts = "TRIM(CONCAT(' ', `lastname`, `firstname`, `middlename`))"; $order_crit_file_revisions = "'zzzzzzzzzzzzzz'"; //Revisar $order_crit_calendar = '`subject`'; $order_crit_tasks = '`title`'; $order_crit_milestones = '`name`'; $order_crit_webpages = '`title`'; $order_crit_files = '`filename`'; $order_crit_emails = '`subject`'; $order_crit_comments = '`text`'; $order_crit_messages = '`title`'; $order_crit_workspaces = '`name`'; break; default: $order_crit_companies = '`updated_on`'; $order_crit_contacts = '`updated_on`'; $order_crit_file_revisions = '`updated_on`'; $order_crit_calendar = '`updated_on`'; $order_crit_tasks = '`updated_on`'; $order_crit_milestones = '`updated_on`'; $order_crit_webpages = '`updated_on`'; $order_crit_files = '`updated_on`'; $order_crit_emails = '`received_date`'; $order_crit_comments = '`updated_on`'; $order_crit_messages = '`updated_on`'; $order_crit_workspaces = '`updated_on`'; break; } if ($project instanceof Project) { $proj_ids = $project->getAllSubWorkspacesQuery(true); $proj_cond_companies = Companies::getWorkspaceString($proj_ids); $proj_cond_messages = ProjectMessages::getWorkspaceString($proj_ids); $proj_cond_documents = ProjectFiles::getWorkspaceString($proj_ids); $proj_cond_emails = MailContents::getWorkspaceString($proj_ids); $proj_cond_events = ProjectEvents::getWorkspaceString($proj_ids); $proj_cond_tasks = ProjectTasks::getWorkspaceString($proj_ids); $proj_cond_charts = ProjectCharts::getWorkspaceString($proj_ids); $proj_cond_milestones = ProjectMilestones::getWorkspaceString($proj_ids); $proj_cond_weblinks = ProjectWebpages::getWorkspaceString($proj_ids); $proj_cond_contacts = Contacts::getWorkspaceString($proj_ids); } else { $proj_cond_companies = "true"; $proj_cond_messages = "true"; $proj_cond_documents = "true"; $proj_cond_emails = "true"; $proj_cond_events = "true"; $proj_cond_tasks = "true"; $proj_cond_charts = "true"; $proj_cond_milestones = "true"; $proj_cond_weblinks = "true"; $proj_cond_contacts = "true"; } if ($trashed) { if ($trashed === 'all') { $trashed_cond = '`trashed_on` >= ' . DB::escape(EMPTY_DATETIME); } else { $trashed_cond = '`trashed_on` > ' . DB::escape(EMPTY_DATETIME); } $archived_cond = '1 = 1'; // Show all objects in trash $comments_arch_cond = "1 = 1"; } else { $trashed_cond = '`trashed_on` = ' . DB::escape(EMPTY_DATETIME); if ($archived) { $archived_cond = "`archived_by_id` > 0"; $comments_arch_cond = "1 = 0"; // Don't show comments in archived objects listings } else { $archived_cond = "`archived_by_id` = 0"; $comments_arch_cond = "1 = 1"; } } if (isset($tag) && $tag && $tag != '') { $tag_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag`= " . DB::escape($tag) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = `object_manager_value`) "; } else { $tag_str = ' '; } if ($linkedObject instanceof ProjectDataObject) { $link_id = $linkedObject->getId(); $link_mgr = get_class($linkedObject->manager()); $link_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "linked_objects` `t` WHERE\n\t\t\t(`t`.`object_id`=" . DB::escape($link_id) . " AND `t`.object_manager = " . DB::escape($link_mgr) . " AND `co`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = `object_manager_value`) OR\n\t\t\t(`t`.`rel_object_id`=" . DB::escape($link_id) . " AND `t`.rel_object_manager = " . DB::escape($link_mgr) . " AND `co`.`id` = `t`.`object_id` AND `t`.`object_manager` = `object_manager_value`)) "; } else { $link_str = ' '; } $tag_str .= $link_str; $res = array(); /** If the name of the query ends with Comments it is assumed to be a list of Comments **/ $cfn = ''; if ($filterName != '') { $cfn = " AND text LIKE '%" . $filterName . "%'"; } // Notes if (module_enabled('notes')) { $fn = ''; if ($filterName != '') { $fn = " AND title LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectMessages::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectMessages") { $res['ProjectMessages'] = "SELECT 'ProjectMessages' AS `object_manager_value`, `id` AS `oid`, {$order_crit_messages} AS `order_value` FROM `" . TABLE_PREFIX . "project_messages` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_messages . str_replace('= `object_manager_value`', "= 'ProjectMessages'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectMessagesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectMessages' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_messages` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_messages . str_replace('= `object_manager_value`', "= 'ProjectMessages'", $tag_str) . $permissions . $cfn . ")"; } } // Events if (module_enabled("calendar")) { $fn = ''; if ($filterName != '') { $fn = " AND subject LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectEvents::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectEvents") { $res['ProjectEvents'] = "SELECT 'ProjectEvents' AS `object_manager_value`, `id` AS `oid`, {$order_crit_calendar} AS `order_value` FROM `" . TABLE_PREFIX . "project_events` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_events . str_replace('= `object_manager_value`', "= 'ProjectEvents'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectEventsComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectEvents' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_events` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_events . str_replace('= `object_manager_value`', "= 'ProjectEvents'", $tag_str) . $permissions . $cfn . ")"; } } // Documents if (module_enabled("documents")) { $fn = ''; if ($filterName != '') { $fn = " AND filename LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectFiles::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; $typestring = array_var($_GET, "typestring"); if ($typestring) { $typecond = " AND ((SELECT count(*) FROM `" . TABLE_PREFIX . "project_file_revisions` `pfr` WHERE `" . "pfr`.`type_string` LIKE " . DB::escape($typestring) . " AND `" . "co`.`id` = `pfr`.`file_id`) > 0)"; } else { $typecond = ""; } if ($filterManager == '' || $filterManager == "ProjectFiles") { $res['ProjectFiles'] = "SELECT 'ProjectFiles' AS `object_manager_value`, `id` as `oid`, {$order_crit_files} AS `order_value` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $typecond . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectFilesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectFiles' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $cfn . ")"; } if ($trashed) { $file_rev_docs = "SELECT `id` FROM `" . TABLE_PREFIX . "project_files` `co` WHERE `trashed_by_id` = 0 AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'ProjectFiles'", $tag_str) . $permissions . $typecond; $res['FileRevisions'] = "SELECT 'ProjectFileRevisions' AS `object_manager_value`, `id` AS `oid`, {$order_crit_file_revisions} AS `order_value` FROM `" . TABLE_PREFIX . "project_file_revisions` `co` WHERE {$trashed_cond} AND `file_id` IN (" . $file_rev_docs . ")"; } } // Tasks and Milestones if (module_enabled("tasks")) { $fn = ''; if ($filterName != '') { $fn = " AND title LIKE '%" . $filterName . "%'"; } $completed = $trashed || $archived ? '' : 'AND `completed_on` = ' . DB::escape(EMPTY_DATETIME); $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectTasks::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectTasks") { $res['ProjectTasks'] = "SELECT 'ProjectTasks' AS `object_manager_value`, `id` AS `oid`, {$order_crit_tasks} AS `order_value` FROM `" . TABLE_PREFIX . "project_tasks` `co` WHERE `is_template` = false {$completed} AND " . $trashed_cond . " AND {$archived_cond} AND `is_template` = false AND " . $proj_cond_tasks . str_replace('= `object_manager_value`', "= 'ProjectTasks'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectTasksComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectTasks' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_tasks` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND `is_template` = false AND " . $proj_cond_tasks . str_replace('= `object_manager_value`', "= 'ProjectTasks'", $tag_str) . $permissions . $cfn . ")"; } $fn = ''; if ($filterName != '') { $fn = " AND name LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectMilestones::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectMilestones") { $res['ProjectMilestones'] = "SELECT 'ProjectMilestones' AS `object_manager_value`, `id` AS `oid`, {$order_crit_milestones} AS `order_value` FROM `" . TABLE_PREFIX . "project_milestones` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND `is_template` = false AND " . $proj_cond_milestones . str_replace('= `object_manager_value`', "= 'ProjectMilestones'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectMilestonesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectMilestones' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_milestones` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND `is_template` = false AND " . $proj_cond_milestones . str_replace('= `object_manager_value`', "= 'ProjectMilestones'", $tag_str) . $permissions . $cfn . ")"; } } // Weblinks if (module_enabled("weblinks")) { $fn = ''; if ($filterName != '') { $fn = " AND title LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectWebpages::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "ProjectWebpages") { $res['ProjectWebPages'] = "SELECT 'ProjectWebPages' AS `object_manager_value`, `id` AS `oid`, {$order_crit_webpages} AS `order_value` FROM `" . TABLE_PREFIX . "project_webpages` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_weblinks . str_replace('= `object_manager_value`', "= 'ProjectWebpages'", $tag_str) . $permissions . $fn; } if ($filterManager == '' || $filterManager == "Comments") { $res['ProjectWebPagesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'ProjectWebpages' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "project_webpages` `co` WHERE " . $trashed_cond . " AND {$comments_arch_cond} AND " . $proj_cond_weblinks . str_replace('= `object_manager_value`', "= 'ProjectWebpages'", $tag_str) . $permissions . $cfn . ")"; } } // Email if (module_enabled("email")) { $fn = ''; if ($filterName != '') { $fn = " AND subject LIKE '%" . $filterName . "%'"; } $permissions = ' AND ( ' . permissions_sql_for_listings(MailContents::instance(), ACCESS_LEVEL_READ, logged_user(), $project instanceof Project ? $project->getId() : 0, '`co`') . ')'; if ($filterManager == '' || $filterManager == "MailContents") { $res['MailContents'] = "SELECT 'MailContents' AS `object_manager_value`, `id` AS `oid`, {$order_crit_emails} AS `order_value` FROM `" . TABLE_PREFIX . "mail_contents` `co` WHERE (" . $trashed_cond . " AND {$archived_cond} AND `is_deleted` = 0 AND " . $proj_cond_emails . str_replace('= `object_manager_value`', "= 'MailContents'", $tag_str) . $permissions . ") {$fn}"; } if ($filterManager == '' || $filterManager == "Comments") { $res['MailContentsComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'MailContents' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "mail_contents` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_emails . str_replace('= `object_manager_value`', "= 'MailContents'", $tag_str) . $permissions . $cfn . ")"; } } // Conacts and Companies if (module_enabled("contacts")) { $fn = ''; $fn2 = ''; if ($filterName != '') { $fn = " AND firstname LIKE '%" . $filterName . "%'"; $fn2 = " AND name LIKE '%" . $filterName . "%'"; } // companies $permissions = ' AND ( ' . permissions_sql_for_listings(Companies::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "Companies") { $res['Companies'] = "SELECT 'Companies' AS `object_manager_value`, `id` as `oid`, {$order_crit_companies} AS `order_value` FROM `" . TABLE_PREFIX . "companies` `co` WHERE " . $trashed_cond . " AND {$archived_cond} AND " . $proj_cond_companies . str_replace('= `object_manager_value`', "= 'Companies'", $tag_str) . $permissions . $fn2; } $res['CompaniesComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'Companies' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "companies` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'Companies'", $tag_str) . $permissions . $cfn . ")"; // contacts $permissions = ' AND ( ' . permissions_sql_for_listings(Contacts::instance(), ACCESS_LEVEL_READ, logged_user(), '`project_id`', '`co`') . ')'; if ($filterManager == '' || $filterManager == "Contacts") { $res['Contacts'] = "SELECT 'Contacts' AS `object_manager_value`, `id` AS `oid`, {$order_crit_contacts} AS `order_value` FROM `" . TABLE_PREFIX . "contacts` `co` WHERE {$trashed_cond} AND {$archived_cond} AND {$proj_cond_contacts} " . str_replace('= `object_manager_value`', "= 'Contacts'", $tag_str) . $permissions . $fn; } $res['ContactsComments'] = "SELECT 'Comments' AS `object_manager_value`, `id` AS `oid`, {$order_crit_comments} AS `order_value` FROM `" . TABLE_PREFIX . "comments` WHERE {$trashed_cond} AND `rel_object_manager` = 'Contacts' AND `rel_object_id` IN (SELECT `co`.`id` FROM `" . TABLE_PREFIX . "contacts` `co` WHERE `trashed_by_id` = 0 AND {$comments_arch_cond} AND " . $proj_cond_documents . str_replace('= `object_manager_value`', "= 'Contacts'", $tag_str) . $permissions . $cfn . ")"; } // Workspaces (only for archived objects view) if ($archived) { if ($filterManager == '' || $filterManager == "Projects") { $res['Projects'] = "SELECT 'Projects' AS `object_manager_value`, `id` AS `oid`, {$order_crit_workspaces} AS `order_value` FROM `" . TABLE_PREFIX . "projects` `co` WHERE `completed_on` <> " . DB::escape(EMPTY_DATETIME) . " AND `id` IN (" . logged_user()->getWorkspacesQuery() . ")"; } } if ($count) { foreach ($res as $p => $q) { $res[$p] = "SELECT count(*) AS `quantity`, '{$p}' AS `objectName` FROM ( {$q} ) `table_alias`"; } } return $res; }
<?php $panel = TabPanels::instance()->findById('documents-panel'); if ($panel instanceof TabPanel && $panel->getEnabled()) { $limit = 5; $result = ProjectFiles::instance()->listing(array("extra_conditions" => "AND updated_by_id > 0", "order" => "updated_on", "order_dir" => "desc", "start" => 0, "limit" => $limit)); $active_members = array(); $context = active_context(); foreach ($context as $selection) { if ($selection instanceof Member) { $active_members[] = $selection; } } if (count($active_members) > 0) { $mnames = array(); $allowed_contact_ids = array(); foreach ($active_members as $member) { $mnames[] = clean($member->getName()); } $widget_title = lang('documents') . ' ' . lang('in') . ' ' . implode(", ", $mnames); } $total = $result->total; $documents = $result->objects; $genid = gen_id(); if ($total) { include_once 'template.php'; } }
/** * Gets project files that satisfy condition and that the user can read * * @param unknown_type $condition */ function getUserFiles($user = null, $workspace = null, $tag = null, $type_string = null, $order = null, $orderdir = 'ASC', $offset = 0, $limit = 0, $include_sub_workspaces = true, $archived = false) { if (!$user instanceof User) { $user = logged_user(); } if ($workspace instanceof Project) { if ($include_sub_workspaces) { $wsids = $workspace->getAllSubWorkspacesQuery(!$archived); } else { $wsids = "" . $workspace->getId(); } $wscond = " AND " . self::getWorkspaceString($wsids); } else { $wscond = ""; } if ($tag == '' || $tag == null) { $tagcond = ""; } else { $tagcond = " AND (SELECT count(*) FROM `" . TABLE_PREFIX . "tags` WHERE `" . TABLE_PREFIX . "project_files`.`id` = `" . TABLE_PREFIX . "tags`.`rel_object_id` AND `" . TABLE_PREFIX . "tags`.`tag` = " . DB::escape($tag) . " AND `" . TABLE_PREFIX . "tags`.`rel_object_manager` ='ProjectFiles' ) > 0 "; } if ($type_string == '' || $type_string == null) { $typecond = ""; } else { $types = explode(',', $type_string); $typessql = '('; $cant = count($types); $n = 0; foreach ($types as $type) { $type .= '%'; $typessql .= ' ' . TABLE_PREFIX . "project_file_revisions.type_string LIKE " . DB::escape($type); $n++; $n != $cant ? $typessql .= ' OR ' : ($typessql .= ' )'); } $typecond = " AND (SELECT count(*) FROM " . TABLE_PREFIX . "project_file_revisions WHERE " . $typessql . " AND " . TABLE_PREFIX . "project_files.id = " . TABLE_PREFIX . "project_file_revisions.file_id)"; } $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectFiles::instance(), ACCESS_LEVEL_READ, $user) . ') '; if ($archived) { $archived_cond = " `archived_by_id` <> 0"; } else { $archived_cond = " `archived_by_id` = 0"; } $conditions = $archived_cond . $wscond . $tagcond . $typecond . $permissions; if ($order == self::ORDER_BY_POSTTIME) { $order_by = '`created_on` ' . $orderdir; } else { if ($order == self::ORDER_BY_MODIFYTIME) { $order_by = '`updated_on` ' . $orderdir; } else { $order_by = '`filename`' . $orderdir; } } return self::findAll(array('conditions' => $conditions, 'order' => $order_by, 'offset' => $offset, 'limit' => $limit)); }
<?php $limit = 5; $result = ProjectFiles::instance()->listing(array("order" => "name", "order_dir" => "asc", "start" => 0, "limit" => $limit)); $total = $result->total; $documents = $result->objects; $genid = gen_id(); if ($total) { include_once 'template.php'; }
/** * Return manager instance * * @access protected * @param void * @return ProjectFiles */ function manager() { if(!($this->manager instanceof ProjectFiles)) $this->manager = ProjectFiles::instance(); return $this->manager; } // manager