function getChildren(&$modx, $parent, $deltime = 0) { if (empty($deltime)) { $deltime = time(); } $success = false; $kids = $modx->getCollection('modResource', array('parent' => $parent, 'deleted' => true)); if (count($kids) > 0) { /* the resource has children resources, we'll need to undelete those too */ foreach ($kids as $kid) { $locked = $kid->addLock(); if ($locked !== true) { $user = $modx->getObject('modUser', $locked); if ($user) { $modx->error->failure($modx->lexicon('resource_locked_by', array('id' => $kid->get('id'), 'user' => $user->get('username')))); } } $kid->set('deleted', 0); $kid->set('deletedby', 0); $kid->set('deletedon', 0); $success = $kid->save(); if ($success) { $success = getChildren($modx, $kid->get('id'), $deltime); } } } return $success; }
public function menuData() { //authcheck($url); /* 列出所有节点 */ $ids = isset($_POST['id']) ? $this->_post('id') : $this->_get('id'); $id = isset($_POST['id']) || isset($_GET['id']) ? intval($ids) : 0; $map['pid'] = array('eq', $id); $map['tree'] = array('eq', 1); $db = M('auth_rule'); /* 如果是超级用户,所有列表 */ if (session('id') == C('SUPER_ADMIN')) { $result = $db->field('iconCls,id,level,name,action,pid,sort,tree,title text,whetherclick')->where($map)->order('sort asc')->select(); } else { //否则通过权限查看 $accessList = getAccessNodeList(session('id')); $map['id'] = array('in', $accessList); $result = $db->field('iconCls,id,level,name,action,pid,sort,tree,title text,whetherclick')->where($map)->order('sort asc')->select(); //dump($result);die; } for ($i = 0; $i < count($result); $i++) { /* 加入result[i][attributes][url] 节点 */ $result[$i]['attributes']['name'] = $result[$i]['name']; $result[$i]['attributes']['whetherclick'] = $result[$i]['whetherclick']; /* 加入state节点 */ if (getChildren($db, $result[$i]['id'])) { $result[$i]['state'] = 'closed'; } else { $result[$i]['state'] = 'open'; } } $this->ajaxReturn($result); }
function getChildren($parent) { global $dbase; global $table_prefix; global $children; global $site_start; global $site_unavailable_page; $db->debug = true; $sql = "SELECT id FROM {$dbase}.`" . $table_prefix . "site_content` WHERE {$dbase}.`" . $table_prefix . "site_content`.parent=" . $parent . " AND deleted=0;"; $rs = mysql_query($sql); $limit = mysql_num_rows($rs); if ($limit > 0) { // the document has children documents, we'll need to delete those too for ($i = 0; $i < $limit; $i++) { $row = mysql_fetch_assoc($rs); if ($row['id'] == $site_start) { echo "The document you are trying to delete is a folder containing document " . $row['id'] . ". This document is registered as the 'Site start' document, and cannot be deleted. Please assign another document as your 'Site start' document and try again."; exit; } if ($row['id'] == $site_unavailable_page) { echo "The document you are trying to delete is a folder containing document " . $row['id'] . ". This document is registered as the 'Site unavailable page' document, and cannot be deleted. Please assign another document as your 'Site unavailable page' document and try again."; exit; } $children[] = $row['id']; getChildren($row['id']); //echo "Found childNode of parentNode $parent: ".$row['id']."<br />"; } } }
function getChildren($parent) { global $modx; global $children; global $site_start; global $site_unavailable_page; global $error_page; global $unauthorized_page; $rs = $modx->db->select('id', $modx->getFullTableName('site_content'), "parent={$parent} AND deleted=0"); // the document has children documents, we'll need to delete those too while ($childid = $modx->db->getValue($rs)) { if ($childid == $site_start) { $modx->webAlertAndQuit("The document you are trying to delete is a folder containing document {$childid}. This document is registered as the 'Site start' document, and cannot be deleted. Please assign another document as your 'Site start' document and try again."); } if ($childid == $site_unavailable_page) { $modx->webAlertAndQuit("The document you are trying to delete is a folder containing document {$childid}. This document is registered as the 'Site unavailable page' document, and cannot be deleted. Please assign another document as your 'Site unavailable page' document and try again."); } if ($childid == $error_page) { $modx->webAlertAndQuit("The document you are trying to delete is a folder containing document {$childid}. This document is registered as the 'Site error page' document, and cannot be deleted. Please assign another document as your 'Site error page' document and try again."); } if ($childid == $unauthorized_page) { $modx->webAlertAndQuit("The document you are trying to delete is a folder containing document {$childid}. This document is registered as the 'Site unauthorized page' document, and cannot be deleted. Please assign another document as your 'Site unauthorized page' document and try again."); } $children[] = $childid; getChildren($childid); //echo "Found childNode of parentNode $parent: ".$childid."<br />"; } }
function getChildren($rowAll, $visualAssessmentTermIDParent, $level = 0, $studentResults = null) { $childrenCount = 0; $json = ''; $jsonInt = ''; $json = $json = ',"children": ['; foreach ($rowAll as $row) { if ($row['visualAssessmentTermIDParent'] == $visualAssessmentTermIDParent) { ++$childrenCount; $title = addslashes($row['term']); if ($row['description'] != '') { $title = addslashes($row['term']) . ' - ' . addslashes($row['description']); } $jsonInt .= '{"name": "' . $row['term'] . '", "class": "' . $row['visualAssessmentTermID'] . '", "level": "' . $level . '", "title": "' . $title . '"'; if ($studentResults != null) { foreach ($studentResults as $studentResult) { if ($studentResult['visualAssessmentTermID'] == $row['visualAssessmentTermID']) { $jsonInt .= ', "attainment": "' . 'attainment' . $studentResult['attainment'] . '"'; exit; } } } $jsonInt .= getChildren($rowAll, $row['visualAssessmentTermID'], $level + 1, $studentResults); $jsonInt .= '},'; } } if ($jsonInt != '') { $jsonInt = substr($jsonInt, 0, -1); } $json .= $jsonInt; $json .= ']'; return $json; }
function generateSubmenu($pageId, $parentPath) { $ret = '<div class="cms-breadcrumbsubmenu"><ul>'; global $userId; $children = getChildren($pageId, $userId); foreach ($children as $child) { $ret .= "<li><span><a href='{$parentPath}{$child[1]}'>{$child[2]}</a></span></li><br>"; } $ret .= '</ul></div>'; return $ret; }
function getNumberOfTrees($tree) { $result = 0; foreach ($tree as $value) { if (getChildren($value) % 2 == 0) { $result++; } $result = $result + getNumberOfTrees($value); } return $result; }
function getXmlTree($file) { $data = implode("", file($file)); $xml = xml_parser_create(); xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($xml, $data, $vals, $index); xml_parser_free($xml); $tree = array(); $i = 0; array_push($tree, array('tag' => $vals[$i]['tag'], 'attributes' => $vals[$i]['attributes'], 'children' => getChildren($vals, $i))); return $tree; }
function getChildren($children) { if (!$children) { return ''; } $childrenVal = '<ul class="list-unstyled">'; foreach ($children as $child) { $childrenVal .= '<li><strong>' . $child->description . '</strong> (<a href="' . \yii\helpers\Url::to(['view', 'id' => $child->name]) . '">' . $child->name . '</a>)</li>'; $childrenVal .= getChildren($child->getChildren()->orderBy(['type' => SORT_ASC, 'name' => SORT_ASC])->all()); } return $childrenVal . '</ul><br />'; }
function getChildren($groupid) { global $metricid; $haschildren = false; $sql = "SELECT description,id,parent_id,1 as type,'' as full_name,'' as country FROM entity_groups where id=" . $groupid; $result = mysql_query($sql); $e = mysql_fetch_assoc($result); $output[] = $e; $sql = "SELECT description,id,parent_id,1 as type,'' as full_name,'' as country FROM entity_groups where parent_id=" . $groupid; $sql .= " order by description "; $result = mysql_query($sql); while ($e = mysql_fetch_assoc($result)) { $tmp = getChildren($e['id']); if (!empty($tmp)) { foreach ($tmp as $item) { $output[] = $item; $haschildren = true; } } } $sql = "select ticker as description,entities.id,entity_group_id as parent_id,2 as type,full_name,countries.name as country "; $sql .= "from entities "; $sql .= "JOIN entities_entity_groups on entities.id=entities_entity_groups.entity_id "; //$sql.= "LEFT join countries on countries.id=entities.country_id "; $sql .= " LEFT join countries_entities on countries_entities.entity_id=entities.id "; $sql .= " LEFT join countries on countries_entities.country_id=countries.id "; if (!empty($metricid)) { $sql .= "JOIN entities_metrics on entities_metrics.entity_id = entities.id "; } $sql .= " where entities_entity_groups.entity_group_id=" . $groupid; if (!empty($metricid)) { $sql .= " and entities_metrics.metric_id =" . $metricid; } //OFP 2/12/2012 - Had to add the following for USDXCD which was an example of an entity associated //with multiple countries and would result in invalid duplicate entires being returned in this query. $sql .= " and (countries_entities.default_country=1 OR countries_entities.default_country is null)"; $sql .= " order by description "; //echo $sql; $result = mysql_query($sql); if ($result != null) { while ($e = mysql_fetch_assoc($result)) { $output[] = $e; $haschildren = true; } } if ($haschildren == false) { //if this node has no children, remove it. array_pop($output); } return $output; //echo "<BR> schedule id: ".$q."<BR>"; //echo "<table border='1'>"; }
function getChildren($parent) { global $modx; global $children; global $deltime; $rs = $modx->db->select('id', $modx->getFullTableName('site_content'), "parent='{$parent}' AND deleted=1 AND deletedon='{$deltime}'"); // the document has children documents, we'll need to delete those too while ($row = $modx->db->getRow($rs)) { $children[] = $row['id']; getChildren($row['id']); //echo "Found childNode of parentNode $parent: ".$row['id']."<br />"; } }
function getChildren($itemMenu) { $tmp = ""; $filhos = $itemMenu->getChildren(); if (!empty($filhos)) { $tmp = "<ul>"; foreach ($filhos as $value) { $tmp .= "<li style='display:block !important'>" . $value->get('title') . "</li>"; $tmp .= getChildren($value); } $tmp .= "</ul>"; } return $tmp; }
function getChildren($parent) { global $children; global $deltime, $modx; //$db->debug = true; $rs = $modx->db->select('id', '[+prefix+]site_content', "parent={$parent} AND deleted=1 AND deletedon='{$deltime}'"); if ($modx->db->getRecordCount($rs) > 0) { // the document has children documents, we'll need to delete those too while ($row = $modx->db->getRow($rs)) { $children[] = $row['id']; getChildren($row['id']); } } }
/** * Retrives active categories count * @param Varien_Object| $object * @return integer */ public function __getChildrenCount($object) { if (Mage::getStoreConfig('catalog/frontend/flat_catalog_category')) { if (!$object->getChildrenCount()) { $count = 0; if ($object->getChildrenNodes()) { foreach ($object->getChildrenNodes() as $child) { if ($child->getIsActive()) { $count++; } } return $count; } if ($object->getChildren()) { foreach ($object->getChildren() as $child) { if ($child->getIsActive()) { $count++; } } return $count; } } return $object->getChildrenCount(); } else { if ($object->getChildrenCount()) { $count = 0; foreach ($object->getChildren() as $child) { if ($child->getIsActive()) { $count++; } } return $count; } } return 0; }
function getCategories($d) { global $baseurl, $f, $p, $local, $cats; $topcat = $d->find('#e1 > li'); foreach ($topcat as $top) { //echo $top->innertext . "\n"; $catname = $top->find('a > div', 0)->innertext; $caturl = $top->find('a', 0)->href; $catpath = "|"; $cats[] = array($catname, $catpath, $caturl); // echo "Saved category /" . $catname . "\n"; getProducts($caturl, $catpath . $catname); getChildren($caturl, $catpath . $catname); } }
function createTree($branches) { $tree = array(); foreach ($branches as $slice_id => $slice) { if ($slice['parent_id'] == "0") { $tree[$slice_id] = $slice; unset($branches[$slice_id]); } } $tree = fix_keys(getChildren($branches, $tree)); echo '<hr>'; var_dump($branches); echo '<hr>'; return $tree; }
function getChildren($parent, &$modx, &$children) { if (!is_array($children)) { $children = array(); } $parent->children = $parent->getMany('Children'); if (count($parent->children) > 0) { foreach ($parent->children as $child) { if ($child->get('id') == $modx->getOption('site_start')) { return $modx->error->failure($modx->lexicon('resource_err_delete_container_sitestart', array('id' => $child->get('id')))); } if ($child->get('id') == $modx->getOption('site_unavailable_page')) { return $modx->error->failure($modx->lexicon('document_err_delete_container_siteunavailable', array('id' => $child->get('id')))); } $children[] = $child; /* recursively loop through tree */ getChildren($child, $modx, $children); } } }
function getChildren($parent) { global $dbase; global $table_prefix; global $children; global $deltime; $db->debug = true; $sql = "SELECT id FROM {$dbase}.`" . $table_prefix . "site_content` WHERE {$dbase}.`" . $table_prefix . "site_content`.parent=" . $parent . " AND deleted=1 AND deletedon={$deltime};"; $rs = mysql_query($sql); $limit = mysql_num_rows($rs); if ($limit > 0) { // the document has children documents, we'll need to delete those too for ($i = 0; $i < $limit; $i++) { $row = mysql_fetch_assoc($rs); $children[] = $row['id']; getChildren($row['id']); //echo "Found childNode of parentNode $parent: ".$row['id']."<br />"; } } }
function renderObject($object_id) { global $nextorder, $virtual_obj_types; $info = spotEntity('object', $object_id); amplifyCell($info); // Main layout starts. echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>"; echo "<tr><td colspan=2 align=center><h1>{$info['dname']}</h1></td></tr>\n"; // left column with uknown number of portlets echo "<tr><td class=pcleft>"; // display summary portlet $summary = array(); if (strlen($info['name'])) { $summary['Common name'] = $info['name']; } elseif (considerConfiguredConstraint($info, 'NAMEWARN_LISTSRC')) { $summary[] = array('<tr><td colspan=2 class=msg_error>Common name is missing.</td></tr>'); } $summary['Object type'] = '<a href="' . makeHref(array('page' => 'depot', 'tab' => 'default', 'cfe' => '{$typeid_' . $info['objtype_id'] . '}')) . '">' . decodeObjectType($info['objtype_id']) . '</a>'; if (strlen($info['label'])) { $summary['Visible label'] = $info['label']; } if (strlen($info['asset_no'])) { $summary['Asset tag'] = $info['asset_no']; } elseif (considerConfiguredConstraint($info, 'ASSETWARN_LISTSRC')) { $summary[] = array('<tr><td colspan=2 class=msg_error>Asset tag is missing.</td></tr>'); } $parents = getParents($info, 'object'); // lookup the human-readable object type, sort by it foreach ($parents as $parent_id => $parent) { $parents[$parent_id]['object_type'] = decodeObjectType($parent['objtype_id']); } $grouped_parents = groupBy($parents, 'object_type'); ksort($grouped_parents); foreach ($grouped_parents as $parents_group) { uasort($parents_group, 'compare_name'); $label = $parents_group[key($parents_group)]['object_type'] . (count($parents_group) > 1 ? ' containers' : ' container'); $fmt_parents = array(); foreach ($parents_group as $parent) { $fmt_parents[] = mkCellA($parent); } $summary[$label] = implode('<br>', $fmt_parents); } $children = getChildren($info, 'object'); foreach (groupBy($children, 'objtype_id') as $objtype_id => $children_group) { uasort($children_group, 'compare_name'); $fmt_children = array(); foreach ($children_group as $child) { $fmt_children[] = mkCellA($child); } $summary["Contains " . strtolower(decodeObjectType($objtype_id))] = implode('<br>', $fmt_children); } if ($info['has_problems'] == 'yes') { $summary[] = array('<tr><td colspan=2 class=msg_error>Has problems</td></tr>'); } foreach (getAttrValuesSorted($object_id) as $record) { if (strlen($record['value']) and permitted(NULL, NULL, NULL, array(array('tag' => '$attr_' . $record['id'])))) { $summary['{sticker}' . $record['name']] = formatAttributeValue($record); } } $summary[] = array(getOutputOf('printTagTRs', $info, makeHref(array('page' => 'depot', 'tab' => 'default', 'andor' => 'and', 'cfe' => '{$typeid_' . $info['objtype_id'] . '}')) . "&")); renderEntitySummary($info, 'summary', $summary); if (strlen($info['comment'])) { startPortlet('Comment'); echo '<div class=commentblock>' . string_insert_hrefs($info['comment']) . '</div>'; finishPortlet(); } $logrecords = getLogRecordsForObject($_REQUEST['object_id']); if (count($logrecords)) { startPortlet('log records'); echo "<table cellspacing=0 cellpadding=5 align=center class=widetable width='100%'>"; $order = 'odd'; foreach ($logrecords as $row) { echo "<tr class=row_{$order} valign=top>"; echo '<td class=tdleft>' . $row['date'] . '<br>' . $row['user'] . '</td>'; echo '<td class="logentry">' . string_insert_hrefs(htmlspecialchars($row['content'], ENT_NOQUOTES)) . '</td>'; echo '</tr>'; $order = $nextorder[$order]; } echo '</table>'; finishPortlet(); } switchportInfoJS($object_id); // load JS code to make portnames interactive renderFilesPortlet('object', $object_id); if (count($info['ports'])) { startPortlet('ports and links'); $hl_port_id = 0; if (isset($_REQUEST['hl_port_id'])) { assertUIntArg('hl_port_id'); $hl_port_id = $_REQUEST['hl_port_id']; addAutoScrollScript("port-{$hl_port_id}"); } echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>"; echo '<tr><th class=tdleft>Local name</th><th class=tdleft>Visible label</th>'; echo '<th class=tdleft>Interface</th><th class=tdleft>L2 address</th>'; echo '<th class=tdcenter colspan=2>Remote object and port</th>'; echo '<th class=tdleft>Cable ID</th></tr>'; foreach ($info['ports'] as $port) { callHook('renderObjectPortRow', $port, $hl_port_id == $port['id']); } if (permitted(NULL, 'ports', 'set_reserve_comment')) { addJS('js/inplace-edit.js'); } echo "</table><br>"; finishPortlet(); } if (count($info['ipv4']) + count($info['ipv6'])) { startPortlet('IP addresses'); echo "<table cellspacing=0 cellpadding='5' align='center' class='widetable'>\n"; if (getConfigVar('EXT_IPV4_VIEW') == 'yes') { echo "<tr class=tdleft><th>OS interface</th><th>IP address</th><th>network</th><th>routed by</th><th>peers</th></tr>\n"; } else { echo "<tr class=tdleft><th>OS interface</th><th>IP address</th><th>peers</th></tr>\n"; } // group IP allocations by interface name instead of address family $allocs_by_iface = array(); foreach (array('ipv4', 'ipv6') as $ip_v) { foreach ($info[$ip_v] as $ip_bin => $alloc) { $allocs_by_iface[$alloc['osif']][$ip_bin] = $alloc; } } // sort allocs array by portnames foreach (sortPortList($allocs_by_iface) as $iface_name => $alloclist) { $is_first_row = TRUE; foreach ($alloclist as $alloc) { $rendered_alloc = callHook('getRenderedAlloc', $object_id, $alloc); echo "<tr class='{$rendered_alloc['tr_class']}' valign=top>"; // display iface name, same values are grouped into single cell if ($is_first_row) { $rowspan = count($alloclist) > 1 ? 'rowspan="' . count($alloclist) . '"' : ''; echo "<td class=tdleft {$rowspan}>" . $iface_name . $rendered_alloc['td_name_suffix'] . "</td>"; $is_first_row = FALSE; } echo $rendered_alloc['td_ip']; if (getConfigVar('EXT_IPV4_VIEW') == 'yes') { echo $rendered_alloc['td_network']; echo $rendered_alloc['td_routed_by']; } echo $rendered_alloc['td_peers']; echo "</tr>\n"; } } echo "</table><br>\n"; finishPortlet(); } $forwards = $info['nat4']; if (count($forwards['in']) or count($forwards['out'])) { startPortlet('NATv4'); if (count($forwards['out'])) { echo "<h3>locally performed NAT</h3>"; echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n"; echo "<tr><th>Proto</th><th>Match endpoint</th><th>Translate to</th><th>Target object</th><th>Rule comment</th></tr>\n"; foreach ($forwards['out'] as $pf) { $class = 'trerror'; $osif = ''; $localip_bin = ip_parse($pf['localip']); if (array_key_exists($localip_bin, $info['ipv4'])) { $class = $info['ipv4'][$localip_bin]['addrinfo']['class']; $osif = $info['ipv4'][$localip_bin]['osif'] . ': '; } echo "<tr class='{$class}'>"; echo "<td>{$pf['proto']}</td><td class=tdleft>{$osif}" . getRenderedIPPortPair($pf['localip'], $pf['localport']) . "</td>"; echo "<td class=tdleft>" . getRenderedIPPortPair($pf['remoteip'], $pf['remoteport']) . "</td>"; $address = getIPAddress(ip4_parse($pf['remoteip'])); echo "<td class='description'>"; if (count($address['allocs'])) { foreach ($address['allocs'] as $bond) { echo mkA("{$bond['object_name']}({$bond['name']})", 'object', $bond['object_id']) . ' '; } } elseif (strlen($pf['remote_addr_name'])) { echo '(' . $pf['remote_addr_name'] . ')'; } echo "</td><td class='description'>{$pf['description']}</td></tr>"; } echo "</table><br><br>"; } if (count($forwards['in'])) { echo "<h3>arriving NAT connections</h3>"; echo "<table class='widetable' cellpadding=5 cellspacing=0 border=0 align='center'>\n"; echo "<tr><th>Matched endpoint</th><th>Source object</th><th>Translated to</th><th>Rule comment</th></tr>\n"; foreach ($forwards['in'] as $pf) { echo "<tr>"; echo "<td>{$pf['proto']}/" . getRenderedIPPortPair($pf['localip'], $pf['localport']) . "</td>"; echo '<td class="description">' . mkA($pf['object_name'], 'object', $pf['object_id']); echo "</td><td>" . getRenderedIPPortPair($pf['remoteip'], $pf['remoteport']) . "</td>"; echo "<td class='description'>{$pf['description']}</td></tr>"; } echo "</table><br><br>"; } finishPortlet(); } renderSLBTriplets2($info); renderSLBTriplets($info); echo "</td>\n"; // After left column we have (surprise!) right column with rackspace portlet only. echo "<td class=pcright>"; if (!in_array($info['objtype_id'], $virtual_obj_types)) { // rackspace portlet startPortlet('rackspace allocation'); foreach (getResidentRacksData($object_id, FALSE) as $rack_id) { renderRack($rack_id, $object_id); } echo '<br>'; finishPortlet(); } echo "</td></tr>"; echo "</table>\n"; }
function create($entity) { $html = getHTML($entity['source_url']); if (!$html) { return error_log('Could not import ' + $entity['source_url']); } // Clean title $entity['title'] = trim(html_entity_decode($entity['title'], ENT_COMPAT, 'UTF-8')); // Generate key $entity['key'] = 'ch/' . makeSlug($entity['title']); // Extract email $emailLink = $html->find('table.tabelleESK a[href^=mailto:]', 0); if ($emailLink) { $entity['email'] = str_replace('mailto:', '', trim($emailLink->href)); } // Extract URL foreach ($html->find('table.tabelleESK tr') as $row) { $name = trim($row->children(0)->innertext); if (stripos('homepage', $name) !== false) { foreach ($row->children() as $i => $cell) { $link = $cell->find('a[href]', 0); if ($link) { $entity['url'] = $link->href; break; } // Ugly case: URL but no link if ($i && !$cell->children()) { $entity['url'] = $cell->innertext; break; } } } } // Find entity abbreviation $orgTitle = $html->find('h2.titleOrg', 0); if ($orgTitle) { $orgTitleParts = explode('-', $orgTitle->innertext); if (count($orgTitleParts) > 1) { $entity['abbr'] = trim(array_pop($orgTitleParts)); $entity['abbr'] = html_entity_decode($entity['abbr'], ENT_COMPAT, 'UTF-8'); } } else { error_log('No title on ' + $entity['source_url']); } // Find entity address $infoBlock = $html->find('div.infoblock', 0)->innertext; if (preg_match('/<\\/h2>(.+?)<div class="titleContent">/s', $infoBlock, $matches)) { $infoBlock = str_replace(array('<br>', '(neues Fenster)'), array(', ', ''), $matches[1]); $infoBlock = preg_replace('/\\s\\s+/', ' ', $infoBlock); $infoBlock = trim(html_entity_decode(strip_tags($infoBlock), ENT_COMPAT, 'UTF-8')); $entity['address'] = $infoBlock; } save($entity); getChildren($entity, $html); }
<?php require 'config.php'; //GET DATA FROM ANGULAR $HTTP $postdata = file_get_contents("php://input"); $data = json_decode($postdata)->data; //$data = json_decode('{"data":{"action":"load","owner":1,"root":"1"}}')->data; $action = $data->action; $response = new response(); switch ($action) { case 'load': $owner = intval($data->owner); $root = intval($data->root); if ($response->parts = getChildren($root, $owner)) { } else { $response->error('Could not load Parts'); } break; default: break; } echo json_encode($response); //FINISHED ?> <?php //FUNCTIONS & CLASSES function getChildren($parent, $owner) { global $db;
function getContent($pageId, $action, $userId, $permission, $recursed = 0) { if ($action == "login") { if ($userId == 0) { ///Commented the requirement of login.lib.php because it is already included in /index.php //require_once("login.lib.php"); $newUserId = login(); if (is_numeric($newUserId)) { return getContent($pageId, "view", $newUserId, getPermissions($newUserId, $pageId, "view"), 0); } else { return $newUserId; } ///<The login page } else { displayinfo("You are logged in as " . getUserName($userId) . "! Click <a href=\"./+logout\">here</a> to logout."); } return getContent($pageId, "view", $userId, getPermissions($userId, $pageId, "view"), $recursed = 0); } if ($action == "profile") { if ($userId != 0) { require_once "profile.lib.php"; return profile($userId); } else { displayinfo("You need to <a href=\"./+login\">login</a> to view your profile.!"); } } if ($action == "logout") { if ($userId != 0) { $newUserId = resetAuth(); displayinfo("You have been logged out!"); global $openid_enabled; if ($openid_enabled == 'true') { displaywarning("If you logged in via Open ID, make sure you also log out from your Open ID service provider's website. Until then your session in this website will remain active !"); } return getContent($pageId, "view", $newUserId, getPermissions($newUserId, $pageId, "view"), 0); } else { displayinfo("You need to <a href=\"./+login\">login</a> first to logout!"); } } if ($action == "search") { require_once "search.lib.php"; $ret = getSearchBox(); if (isset($_POST['query'])) { $ret .= getSearchResultString($_POST['query']); } elseif (isset($_GET['query'])) { $ret .= getSearchResultString($_GET['query']); } return $ret; } if (isset($_GET['subaction']) && $_GET['subaction'] == 'getchildren') { if (isset($_GET['parentpath'])) { global $urlRequestRoot; require_once 'menu.lib.php'; $pidarr = array(); parseUrlReal(escape($_GET['parentpath']), $pidarr); $pid = $pidarr[count($pidarr) - 1]; $children = getChildren($pid, $userId); $response = array(); $response['path'] = escape($_GET['parentpath']); $response['items'] = array(); foreach ($children as $child) { $response['items'][] = array($urlRequestRoot . '/home' . escape($_GET['parentpath']) . $child[1], $child[2]); } //echo json_encode($response); exit; } } if ($permission != true) { if ($userId == 0) { $suggestion = "(Try <a href=\"./+login\">logging in?</a>)"; } else { $suggestion = ""; } displayerror("You do not have the permissions to view this page. {$suggestion}<br /><input type=\"button\" onclick=\"history.go(-1)\" value=\"Go back\" />"); return ''; } if ($action == "admin") { require_once "admin.lib.php"; return admin($pageId, $userId); } ///default actions also to be defined here (and not outside) /// Coz work to be done after these actions do involve the page $pagetype_query = "SELECT page_module, page_modulecomponentid FROM " . MYSQL_DATABASE_PREFIX . "pages WHERE page_id='" . escape($pageId) . "'"; $pagetype_result = mysql_query($pagetype_query); $pagetype_values = mysql_fetch_assoc($pagetype_result); if (!$pagetype_values) { displayerror("The requested page does not exist."); return ""; } $moduleType = $pagetype_values['page_module']; $moduleComponentId = $pagetype_values['page_modulecomponentid']; if ($action == "settings") { ///<done here because we needed to check if the page exists for sure. require_once "pagesettings.lib.php"; return pagesettings($pageId, $userId); } if ($action == "widgets") { return handleWidgetPageSettings($pageId); } if ($recursed == 0) { $pagetypeupdate_query = "UPDATE " . MYSQL_DATABASE_PREFIX . "pages SET page_lastaccesstime=NOW() WHERE page_id='" . escape($pageId) . "'"; $pagetypeupdate_result = mysql_query($pagetypeupdate_query); if (!$pagetypeupdate_result) { return '<div class="cms-error">Error No. 563 - An error has occured. Contact the site administators.</div>'; } } if ($moduleType == "link") { return getContent($moduleComponentId, $action, $userId, true, 1); } if ($action == "grant") { return grantPermissions($userId, $pageId); } if ($moduleType == "menu") { return getContent(getParentPage($pageId), $action, $userId, true, 1); } if ($moduleType == "external") { $query = "SELECT `page_extlink` FROM `" . MYSQL_DATABASE_PREFIX . "external` WHERE `page_modulecomponentid` =\n\t\t\t\t\t(SELECT `page_modulecomponentid` FROM `" . MYSQL_DATABASE_PREFIX . "pages` WHERE `page_id`= '" . escape($pageId) . "')"; $result = mysql_query($query); $values = mysql_fetch_array($result); $link = $values[0]; header("Location: {$link}"); } global $sourceFolder; global $moduleFolder; require_once $sourceFolder . "/" . $moduleFolder . "/" . $moduleType . ".lib.php"; $page = new $moduleType(); if (!$page instanceof module) { displayerror("The module \"{$moduleType}\" does not implement the inteface module</div>"); return ""; } $createperms_query = " SELECT * FROM " . MYSQL_DATABASE_PREFIX . "permissionlist where perm_action = 'create' AND page_module = '" . $moduleType . "'"; $createperms_result = mysql_query($createperms_query); if (mysql_num_rows($createperms_result) < 1) { displayerror("The action \"create\" does not exist in the module \"{$moduleType}\"</div>"); return ""; } $availableperms_query = "SELECT * FROM " . MYSQL_DATABASE_PREFIX . "permissionlist where perm_action != 'create' AND page_module = '" . $moduleType . "'"; $availableperms_result = mysql_query($availableperms_query); $permlist = array(); while ($value = mysql_fetch_assoc($availableperms_result)) { array_push($permlist, $value['perm_action']); } array_push($permlist, "view"); $class_methods = get_class_methods($moduleType); foreach ($permlist as $perm) { if (!in_array("action" . ucfirst($perm), $class_methods)) { displayerror("The action \"{$perm}\" does not exist in the module \"{$moduleType}\"</div>"); return ""; } } if ($action == "pdf") { if (isset($_GET['depth'])) { $depth = $_GET['depth']; } else { $depth = 0; } if (!is_numeric($depth)) { $depth = 0; } global $TITLE; global $sourceFolder; require_once "{$sourceFolder}/modules/pdf/html2fpdf.php"; $pdf = new HTML2FPDF(); $pdf->setModuleComponentId($moduleComponentId); $pdf->AddPage(); $pdf->WriteHTML($page->getHtml($userId, $moduleComponentId, "view")); $cp = array(); $j = 0; if ($depth == -1) { $cp = child($pageId, $userId, $depth); if ($cp[0][0]) { for ($i = 0; $cp[$i][0] != NULL; $i++) { require_once $sourceFolder . "/" . $moduleFolder . "/" . $cp[$i][2] . ".lib.php"; $page1 = new $cp[$i][2](); $modCompId = $cp[$i][5]; $pdf->setModuleComponentId($modCompId); $pdf->AddPage(); $pdf->WriteHTML($page1->getHtml($userId, $modCompId, "view")); } } } else { if ($depth > 0) { $cp = child($pageId, $userId, $depth); --$depth; while ($depth > 0) { $count = count($cp); for ($j; $j < $count; $j++) { $cp = array_merge((array) $cp, (array) child($cp[$j][0], $userId, $depth)); } --$depth; } if ($cp[0][0]) { for ($i = 0; isset($cp[$i]); $i++) { require_once $sourceFolder . "/" . $moduleFolder . "/" . $cp[$i][2] . ".lib.php"; $page1 = new $cp[$i][2](); $modCompId = $cp[$i][5]; $pdf->setModuleComponentId($modCompId); $pdf->AddPage(); $pdf->WriteHTML($page1->getHtml($userId, $modCompId, "view")); } } } } $filePath = $sourceFolder . "/uploads/temp/" . $TITLE . ".pdf"; while (file_exists($filePath)) { $filePath = $sourceFolder . "/uploads/temp/" . $TITLE . "-" . rand() . ".pdf"; } $pdf->Output($filePath); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/pdf"); header("Content-Disposition: attachment; filename=\"" . basename($filePath) . "\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($filePath)); @readfile("{$filePath}"); unlink($filePath); } return $page->getHtml($userId, $moduleComponentId, $action); }
function reorderBranches($localhost, $user, $pw, $db, $storyID) { $x = filter_input(INPUT_GET, 'IDs'); $movingIDs = explode(",", $x); $ID01 = $movingIDs[0]; $ID02 = filter_input(INPUT_GET, 'ID'); $found = filter_input(INPUT_GET, 'found'); $con = mysqli_connect($localhost, $user, $pw, $db); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } if ($found == "true") { //get children of targetid $indexedOnly = array(); $hasChildren = true; $indexedOnly = getPage($ID02, "", $storyID, "id ="); $string = $indexedOnly[0]['id']; $string = getChildren($indexedOnly, $hasChildren, $string, $storyID, ""); $string = str_replace($x, "", $string); $targetIDs = explode(",", $string); $targetIDs = array_filter($targetIDs); //get the infos of both main ids $sql = "SELECT id,level,position FROM page WHERE id IN({$ID01},{$ID02}) AND story = " . $storyID; $result = mysqli_query($con, $sql); $indexedOnly = array(); while ($row = mysqli_fetch_assoc($result)) { $indexedOnly[$row['id']] = $row; } $sql = "SELECT id FROM page WHERE NextPageID1 = " . $ID02 . " OR NextPageID2 = " . $ID02 . " OR NextPageID3 = " . $ID02 . " OR NextPageID4 = " . $ID02 . " AND story = " . $storyID; $parentID = array(); if ($indexedOnly[$ID02]['level'] != 0) { $result = mysqli_query($con, $sql); while ($row = mysqli_fetch_assoc($result)) { $parentID[0] = $row['id']; } } $sql = "SELECT id,level,position,NextPageID1 FROM page WHERE id IN({$x}) AND story = " . $storyID . " ORDER BY level ASC"; $result = mysqli_query($con, $sql); $i = array(); while ($row = mysqli_fetch_assoc($result)) { $i[] = $row; } $maxLevel = 0; $maxNodeID = 0; for ($a = 0; $a < sizeof($i); $a++) { if ($i[$a]['level'] > $maxLevel && $i[$a]['position'] == 1) { $maxLevel = $i[$a]['level']; $maxNodeID = $i[$a]['id']; } } $levelDiffmovingIDs = $indexedOnly[$ID02]['level'] - $indexedOnly[$ID01]['level']; $levelDifftargetIDs = $maxLevel + $levelDiffmovingIDs + 1 - $indexedOnly[$ID02]['level']; mysqli_autocommit($con, FALSE); $result = true; $sql = "UPDATE page SET position = CASE id\n WHEN " . $ID01 . " THEN " . $indexedOnly[$ID02]['position'] . "\n WHEN " . $ID02 . " THEN 1\n ELSE position\n END\n WHERE id IN({$ID01},{$ID02}) AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } //changing levels of childpages $movingIDs = array_unique($movingIDs); for ($i = 0; $i < sizeof($movingIDs); $i++) { $sql = "UPDATE page SET level = level+" . $levelDiffmovingIDs . " WHERE id = " . $movingIDs[$i] . " AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } } foreach ($targetIDs as $key => $val) { $sql = "UPDATE page SET level = level+" . $levelDifftargetIDs . " WHERE id = " . $targetIDs[$key] . " AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } } $sql = "UPDATE page SET NextPageID1 = " . $ID02 . " WHERE id = " . $maxNodeID . " AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } $result = fixParentANDSiblings($con, $ID01, $storyID, $result); if ($indexedOnly[$ID02]['level'] != 0) { //austauschen der nextpage ids $sql = "UPDATE page SET NextPageID" . $indexedOnly[$ID02]['position'] . " = " . $ID01 . " WHERE id = " . $parentID[0] . " AND story = " . $storyID; } else { $sql = "UPDATE story SET firstPage = " . $ID01 . " WHERE id = " . $storyID; } if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } if ($result == false) { mysqli_rollback($con); // transaction rolls back echo "Error: Transaction rolled back"; exit; } else { mysqli_commit($con); // transaction is committed echo "Updated data successfully\n"; } SearchDeleteConnection($movingIDs, $storyID, $con, $result); //needed for highlight echo json_encode($targetIDs); do { mysqli_store_result($con); } while (mysqli_next_result($con)); } else { $hasChildren = true; $indexedOnly = getPage($ID02, "", $storyID, "id ="); $string = $indexedOnly[0]['id']; $string = getChildren($indexedOnly, $hasChildren, $string, $storyID, ""); $targetIDs = explode(",", $string); $sql = "SELECT id,level,position FROM page WHERE id IN({$ID01},{$ID02}) AND story = " . $storyID; $result = mysqli_query($con, $sql); $indexedOnly = array(); while ($row = mysqli_fetch_assoc($result)) { $indexedOnly[$row['id']] = $row; } $levelDiffmovingIDs = $indexedOnly[$ID02]['level'] - $indexedOnly[$ID01]['level']; $levelDifftargetIDs = $indexedOnly[$ID01]['level'] - $indexedOnly[$ID02]['level']; //austauschen level und position von obersten nodes mysqli_autocommit($con, FALSE); $result = true; $sql = "UPDATE page SET level = CASE id\n WHEN " . $ID01 . " THEN " . $indexedOnly[$ID02]['level'] . "\n WHEN " . $ID02 . " THEN " . $indexedOnly[$ID01]['level'] . "\n ELSE level\n END\n , position = CASE id\n WHEN " . $ID01 . " THEN " . $indexedOnly[$ID02]['position'] . "\n WHEN " . $ID02 . " THEN " . $indexedOnly[$ID01]['position'] . "\n ELSE position\n END\n WHERE id IN({$ID01},{$ID02}) AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } $movingIDs = array_unique($movingIDs); //changing levels of childpages for ($i = 1; $i < sizeof($movingIDs); $i++) { $sql = "UPDATE page SET level = level+" . $levelDiffmovingIDs . " WHERE id = " . $movingIDs[$i] . " AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } } if (sizeof($targetIDs) > 1) { for ($i = 1; $i < sizeof($targetIDs); $i++) { $sql = "UPDATE page SET level = level+" . $levelDifftargetIDs . " WHERE id = " . $targetIDs[$i] . " AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } } } //austauschen der nextpage ids $sql = "UPDATE page SET NextPageID1 = CASE NextPageID1\n WHEN " . $ID01 . " THEN " . $ID02 . "\n WHEN " . $ID02 . " THEN " . $ID01 . "\n ELSE NextPageID1\n END\n ,NextPageID2 = CASE NextPageID2\n WHEN " . $ID01 . " THEN " . $ID02 . "\n WHEN " . $ID02 . " THEN " . $ID01 . "\n ELSE NextPageID2\n END\n ,NextPageID3 = CASE NextPageID3\n WHEN " . $ID01 . " THEN " . $ID02 . "\n WHEN " . $ID02 . " THEN " . $ID01 . "\n ELSE NextPageID3\n END\n ,NextPageID4 = CASE NextPageID4\n WHEN " . $ID01 . " THEN " . $ID02 . "\n WHEN " . $ID02 . " THEN " . $ID01 . "\n ELSE NextPageID4\n END\n WHERE NextPageID1 IN({$ID01},{$ID02}) OR NextPageID2 IN({$ID01},{$ID02}) OR NextPageID3 IN({$ID01},{$ID02}) OR NextPageID4 IN({$ID01},{$ID02}) AND story = " . $storyID; if ($result == true) { $result = mysqli_query($con, $sql); } else { mysqli_query($con, $sql); } if ($result == false) { mysqli_rollback($con); // transaction rolls back echo "Error: Transaction rolled back"; exit; } else { mysqli_commit($con); // transaction is committed echo "Updated data successfully\n"; } do { mysqli_store_result($con); } while (mysqli_next_result($con)); } mysqli_close($con); }
/** * Function getTreeView * * @description Similar to menu generation code. It recursively fetches pages according to the sitemap, and generates a ul list with drop handlers defined. * * @param pageId The current Page the function is operation on * @param depth depth of the child list to be fetched at each level. Here it is always -1 to fetch till the last element is reached * @param rootUri here it is /. Look into Menu documentation for implementation of the same elsewhere. * @param userId This is just to check the permission. * @param curdepth Current Depth of the recursion * * @return HTML - UL list of the tree structure of pages */ function getTreeView($pageId, $depth, $rootUri, $userId, $curdepth) { global $cmsFolder; global $templateFolder; require_once "menu.lib.php"; if ($depth > 0 || $depth == -1) { if ($curdepth == 1 || $pageId == 0) { $classname = "treeRoot"; } else { $classname = "treeItem"; } $pageRow = getChildren($pageId, $userId); $var = "<ul class='{$classname}'>"; for ($i = 0; $i < count($pageRow); $i += 1) { $newdepth = $curdepth + 1; $var .= "<li><a href=\"./\" class=\"dropme\" onclick=\"return selectItem(event,this)\""; $var .= <<<DROPZONE \t ondragenter="dragEnterHandler(event)" ondragover="dragOverHandler(event)" ondragleave="dragOutHandler(event)" ondrop="dropHandler(event)" id="p{$pageRow[$i][0]}"> DROPZONE; if ($pageRow[$i][3] != NULL) { $var .= "<img src=\"{$rootUri}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/status/weather-clear.png\" />\n "; } else { $var .= "<img src=\"{$rootUri}/{$cmsFolder}/{$templateFolder}/common/icons/16x16/status/dialog-error.png\" width=12 height=12/>\n "; } $var .= "{$pageRow[$i][1]}</a>"; $var .= getTreeView($pageRow[$i][0], $depth == -1 ? $depth : $depth - 1, $rootUri, $userId, $newdepth); $var .= "</li>"; } $var .= "</ul>"; if (count($pageRow) == 0) { return ""; } return $var; } }
function getChildren($catId) { $sql = "SELECT cat_id " . "FROM tbl_category " . "WHERE cat_parent_id = {$catId} "; $result = dbQuery($sql); $cat = array(); if (dbNumRows($result) > 0) { while ($row = dbFetchRow($result)) { $cat[] = $row[0]; // call this function again to find the children $cat = array_merge($cat, getChildren($row[0])); } } return $cat; }
if ($proceed != true) { echo "<div class='error'>"; echo __($guid, 'Your request failed due to a database error.'); echo '</div>'; } else { echo "<div style='text-align: center; text-transform: uppercase; font-size: 25px; margin-top: 25px; margin-bottom: 0px; color: #4883B5'>"; echo $row['name'] . '<br/>'; echo "<div style='font-size: 65%; font-style: italic; color: #666; text-transform: none'>"; echo $row['description']; if ($gibbonPersonID != null) { echo ' for ' . formatName('', $row3['preferredName'], $row3['surname'], 'Student') . ' (' . $row3['rollGroup'] . ')'; } echo '</div>'; echo '</div>'; $myjson = '{"name": ""'; $myjson .= getChildren($row2All, null, 0, $studentResults); $myjson .= '}'; echo '<script type="text/javascript" src="./modules/Visual Assessment/js/d3/d3.min.js"></script>'; ?> <div id='tree' style='padding-top: 120px; border: 1px solid #000; background: #BADBFB url("./modules/Visual Assessment/img/bg.png") no-repeat right top; text-align: center; width: 1000px; height: 1020px ; margin: 30px auto; font-weight: normal'></div> <style> .attainment1 { fill: #669900!important; font-weight: bold ; } .attainment2 { fill: #FF9102!important; font-weight: bold ; } .attainment3 { fill: #CD3301!important;
function getContent($params) { /* Return specified rows from the table 'content'. -- ALL ARE OPTIONAL -- contentid (int) - specifies a specific content id to return (can be comma-delimited) parentid (int) - only return content under this parent id (can be comma-delimited) - This also overrrides contentid!!! includechildren (0,1) - only applies when a contentid or parentid is specified, do we return children as well? has_tag - comma-delimited list of tags to search for. search_terms - search words to search for (comma-delimited). this searches title, description + custom fields. search_description - search words to search for in description (comma-delimited). search_customfields - words to search for in the custom fields (comma-delimited). verbosity - (1 = ids + titles only, 2 - all fields + named custom fields, 3 - all fields). orderby - field name to order results by, should be expressed as table.field (e.g. content.migtitle). Can also be comma-delimited list. customfield* OR customfieldname (as it appears in DB) will both work for returning content based on custom field data. */ global $arrVerbosity, $arrCFFlag; $validParams = array("action", "contentid", "include_children", "typeid", "has_tag", "search_terms", "thumbUsage", "search_description", "search_title", "search_customfields", "verbosity", "parentid", "orderby", "orderdirection", "children_depth"); // SELECT fields according to verbosity if (!isset($params['verbosity'])) { // set default verbosity $params['verbosity'] = 0; } if (isset($arrCFFlag[$params['verbosity']])) { $sql = "SELECT customfields.name, customfields.displayname\n\t\t\t\tFROM templates_customfields " . "LEFT JOIN customfields ON customfields.id = templates_customfields.customfieldid"; $result = queryDatabase($sql); $customfields = array(); if ($result->rowCount() > 0) { // make sure some custom fields exist! while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $customfields[] = $row['name']; } } } if (isset($params['parentid'])) { // for this we need to get all contentids which have a particular parentid, and then get all their children! $sendParams = array(); //params to replace placeholders at queryDatabase() $sql = "SELECT id FROM content WHERE parentid IN ( "; // $params['parentid'] can be comma-delimited $manyvalues = explode(",", $params['parentid']); foreach ($manyvalues as $contentvalue) { $sql .= " :singlevalue" . $contentvalue . ", "; $sendParams['singlevalue' . $contentvalue] = $contentvalue; } $sql = substr($sql, 0, strlen($sql) - 2); //remove last comma and space $sql .= " )"; $result = queryDatabase($sql, $sendParams); $arrContentIDs = array(); if ($result->rowCount() > 0) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) { $arrContentIDs[] = $row['id']; /*if (isset($params['include_children']) && ($params['include_children'] == 1)) { if(isset($params['children_depth'])) { $children_depth = $params['children_depth']; } $currentChildIDs = getChildren($row['id']); $arrContentIDs = array_merge($arrContentIDs,$currentChildIDs); }*/ } $params['contentid'] = implode(",", $arrContentIDs); } else { $params['contentid'] = "0"; } } $sendParams = array(); //params to replace placeholders at queryDatabase() $i = 0; if (isset($params['include_children']) && isset($params['contentid']) && $params['include_children'] == 1) { // include_children // get childids for all contentids specified $contentids = explode(",", $params['contentid']); $childids = array(); foreach ($contentids as $id) { $currentChildIDs = getChildren($id, $params['children_depth']); $childids = array_merge($childids, $currentChildIDs); $sql2 = "SELECT COUNT(*) as count FROM `content` WHERE parentid = " . $id; $result2 = queryDatabase($sql2); $row2 = $result2->fetch(PDO::FETCH_ASSOC); $childrencount[$id] = $row['count']; } if ($childids) { // make sure we actually got some results $strChildIDs = implode(",", $childids); } } // BUILD SELECT STATEMENT FROM INFO IN VERBOSITY ARRAY! $sql = "SELECT "; if (@is_array($arrVerbosity[$params['verbosity']])) { foreach ($arrVerbosity[$params['verbosity']] as $field) { $sql .= $field . ","; } } else { die("Invalid verbosity level."); } // give us back the custom fields with appropriate names! if (isset($arrCFFlag[$params['verbosity']])) { foreach ($customfields as $key => $value) { $sql .= " content." . $value . ","; } } // remove last comma! $sql = substr($sql, 0, strlen($sql) - 1); //,GROUP_CONCAT(DISTINCT media.path,media.name) AS thumbtitle $includeThumb = true; if (isset($params["thumbUsage"])) { $thumb_usage = $params["thumbUsage"]; $includeThumb = false; } $thumb_usage = "thumb"; //echo $params["contentid"]; $sql .= " FROM content\n\t\t\t LEFT JOIN content_users ON content_users.contentid = content.id\n\t\t\t LEFT JOIN user ON user.id = content_users.userid\n\t\t\t \t\t\t \n\t\t\t LEFT JOIN content_terms AS content_terms ON content_terms.contentid = content.id\n\t\t\t LEFT JOIN term_taxonomy AS term_taxonomy ON term_taxonomy.id = content_terms.termid \n\t\t\t LEFT JOIN terms AS terms ON terms.id = term_taxonomy.termid\n\t\t\t LEFT JOIN templates ON templates.id = content.templateid "; if (isset($params['contentid'])) { $sql .= " LEFT JOIN ( SELECT parentid, COUNT(*) AS childrencount FROM `content` WHERE parentid IN (" . $params['contentid'] . ") AND `content`.`deleted` = '0' GROUP BY parentid\n\t\t\t\t ) AS childrencount ON childrencount.parentid = content.id"; } //related content $sql .= "\n\t\t\t LEFT JOIN (\n\t\n\t\t\t\tSELECT content_content.contentid,GROUP_CONCAT(content_content.contentid2 ORDER BY content_content.id) AS contentids,\n\t\t\t\tGROUP_CONCAT(related.migtitle) AS relatedcontent,content_content.desc \n\t\t\t\tFROM content_content\n\t\t\t\tLEFT JOIN content AS related ON related.id = content_content.contentid2\n\t\t\t\tGROUP BY content_content.contentid\n\t\t\t\n \t\t\t ) AS content1 ON content1.contentid = content.id\n\n\t\t\t LEFT JOIN (\n\t\n\t\t\t\tSELECT content_content.contentid2,GROUP_CONCAT(content_content.contentid ORDER BY content_content.id) AS contentids, \n\t\t\t\tGROUP_CONCAT(related.migtitle) AS relatedcontent, content_content.desc FROM content_content\n\t\t\t\tLEFT JOIN content AS related ON related.id = content_content.contentid\n\t\t\t\tGROUP BY content_content.contentid2\n\t\t\t\n \t\t\t ) AS content2 ON content2.contentid2 = content.id\n\t\t\n\t\t\t \n\t\t\t LEFT JOIN (\n\t\t\t \t\n\t\t\t \t\tSELECT content_media.contentid,GROUP_CONCAT(content_media.mediaid ORDER BY content_media.displayorder) AS mediaids \n\t\t\t \t\tFROM content_media"; if ($includeThumb == false) { $sql .= " WHERE content_media.usage_type <> '" . $thumb_usage . "' "; } $sql .= " GROUP BY content_media.contentid\n\t\t\t \t\t\t\n\t\t\t ) AS content_mediaids ON content_mediaids.contentid = content.id\n\t\t\t \n\t\t\t LEFT JOIN (\n\t\t\t \t\n\t\t\t \t\tSELECT content_media.contentid,GROUP_CONCAT(content_media.mediaid ORDER BY content_media.displayorder) AS thumbids,GROUP_CONCAT(CONCAT(media.path,media.name)) as thumbs\n\t\t\t \t\tFROM content_media\n\t\t\t \t\tLEFT JOIN media ON media.id = content_media.mediaid\n\t\t\t \t\tGROUP BY content_media.contentid\n\t\t\t \t\n\t\t\t ) AS content_thumbids ON content_thumbids.contentid = content.id\n\t\t\t LEFT JOIN media ON media.id = thumbids "; // WHERE CLAUSE INFO $sql .= " WHERE content.id <> 1 AND is_revision <> 1"; if (isset($params['contentid'])) { // return a specific content id, or a list thereof if (isset($strChildIDs)) { $sql .= " AND content.id IN ( "; // $params['contentid'] comma-delimited $manyvalues = explode(",", $params['contentid']); foreach ($manyvalues as $contentvalue) { $sql .= " :singlevalue" . $contentvalue . ", "; $sendParams['singlevalue' . $contentvalue] = $contentvalue; } // $childids comma-delimited foreach ($childids as $childvalue) { $sql .= " :singlevalue" . $childvalue . ", "; $sendParams['singlevalue' . $childvalue] = $childvalue; } $sql = substr($sql, 0, strlen($sql) - 2); //remove last comma and space $sql .= " )"; } else { $sql .= " AND content.id IN ( "; $manyvalues = explode(",", $params['contentid']); foreach ($manyvalues as $value) { $sql .= " :singlevalue" . $value . ", "; $sendParams['singlevalue' . $value] = $value; } $sql = substr($sql, 0, strlen($sql) - 2); //remove last comma and space $sql .= " )"; } } if (isset($params['has_tag'])) { // search for tags $arrTags = explode(",", $params['has_tag']); if (is_array($arrTags)) { $strTags = ""; foreach ($arrTags as $tag) { $strTags .= "'" . $tag . "'"; } $sql .= " AND tags.tag IN (" . $strTags . ") "; } } if (isset($params['search_terms'])) { // general search $arrSearchTerms = explode(",", $params['search_terms']); if (is_array($arrSearchTerms)) { $sql .= " AND ( "; foreach ($arrSearchTerms as $term) { $i++; $sql .= " content.migtitle LIKE :term" . $i . " OR"; $sql .= " content.containerpath LIKE :term" . $i . " OR"; $sql .= " content1.desc LIKE :term" . $i . " OR"; $sql .= " content2.desc LIKE :term" . $i . " OR"; $sql .= " content.customfield1 LIKE :term" . $i . " OR"; $sql .= " content.customfield2 LIKE :term" . $i . " OR"; $sql .= " content.customfield3 LIKE :term" . $i . " OR"; $sql .= " content.customfield4 LIKE :term" . $i . " OR"; $sql .= " content.customfield5 LIKE :term" . $i . " OR"; $sql .= " content.customfield6 LIKE :term" . $i . " OR"; $sql .= " content.customfield7 LIKE :term" . $i . " OR"; $sql .= " content.customfield8 LIKE :term" . $i . " OR"; $sql .= " terms.name LIKE :term" . $i . " OR"; $sendParams['term' . $i] = "%" . $term . "%"; } // remove last "OR" $sql = substr($sql, 0, strlen($sql) - 2); $sql .= " ) "; } } if (isset($params['search_customfields'])) { // search customfields $arrSearchTerms = explode(",", $params['search_customfields']); if (is_array($arrSearchTerms)) { $sql .= " AND ( "; foreach ($arrSearchTerms as $term) { foreach ($customfields as $key => $field) { $sql .= " content.customfield" . $key . " LIKE '%" . $term . "%' OR"; } } // remove last "OR" $sql = substr($sql, 0, strlen($sql) - 2); $sql .= " ) "; } } if (isset($params['search_description'])) { // search description $arrSearchTerms = explode(",", $params['search_description']); if (is_array($arrSearchTerms)) { $sql .= " AND ( "; foreach ($arrSearchTerms as $term) { $i++; $sql .= " content1.desc LIKE :term" . $i . " OR"; $sql .= " content2.desc LIKE :term" . $i . " OR"; $sendParams['term' . $i] = "%" . $term . "%"; } // remove last "OR" $sql = substr($sql, 0, strlen($sql) - 2); $sql .= " ) "; } } if (isset($params['search_title'])) { // search title $arrSearchTerms = explode(",", $params['search_title']); if (is_array($arrSearchTerms)) { $sql .= " AND ( "; foreach ($arrSearchTerms as $term) { $i++; $sql .= " content.migtitle LIKE :term" . $i . " OR"; $sendParams['term' . $i] = "%" . $term . "%"; } // remove last "OR" $sql = substr($sql, 0, strlen($sql) - 2); $sql .= " ) "; } } // GET ANY EXTRA PARAMS AND APPLY THOSE TO THE WHERE CLAUSE! foreach ($params as $key => $value) { if (!in_array($key, $validParams)) { // this is a custom parameter $sql .= " AND " . $key . " = :" . $key; $sendParams[$key] = $value; } } // GROUP BY CLAUSE $sql .= " GROUP BY content.id"; // ORDER BY if (isset($params['orderby'])) { if (isset($params['orderdirection'])) { $sql .= " ORDER BY " . 'content.' . $params['orderby'] . " " . $params['orderdirection']; } else { $sql .= " ORDER BY " . 'content.' . $params['orderby'] . " "; } } else { $sql .= " ORDER BY content.id ASC"; } //echo $sql; $result = queryDatabase($sql, $sendParams); // return the results return $result; }
/** * @param string $categoryCode * * @return array */ function getChildren($categoryCode) { $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY); $categoryCode = Database::escape_string($categoryCode); $result = Database::query("SELECT code, id FROM {$tbl_category} WHERE parent_id = '{$categoryCode}'"); $children = array(); while ($row = Database::fetch_array($result, 'ASSOC')) { $children[] = $row; $subChildren = getChildren($row['code']); $children = array_merge($children, $subChildren); } return $children; }
/** * Get the ChildList for the current item in menu. * @param $pageId the page Id of the current Page * @param $depth The number of levels of menu that should be generated * @param $userId The viewers id - To check for permissions. * @return Associative Array containing the child pages informaion.; */ function getChildList($pageId, $depth, $rootUri, $userId, $curdepth) { if ($depth > 0 || $depth == -1) { if ($curdepth == 1 || $pageId == 0) { $classname = "topnav"; } else { $classname = "subnav"; } $MYHOST = hostURL(); $pageRow = getChildren($pageId, $userId); $var = "<div class='div_{$classname}'><ul class='{$classname} depth{$curdepth}'>"; for ($i = 0; $i < count($pageRow); $i += 1) { $query = "SELECT `page_openinnewtab` FROM `" . MYSQL_DATABASE_PREFIX . "pages` WHERE `page_id` = '{$pageRow[$i][0]}'"; $result = mysql_query($query); $result = mysql_fetch_assoc($result); $opennewtab = ""; if ($result['page_openinnewtab'] == '1') { $opennewtab = ' target="_blank" '; } $newdepth = $curdepth + 1; $imageTag = ''; if ($pageRow[$i][4]) { if ($pageRow[$i][3] != NULL) { $imageTag = "<img width=32 height=32 src=\"{$MYHOST}/{$pageRow[$i][3]}\" alt=\"{$pageRow[$i][1]}\" />"; } /* *@usage: display a default folder icon if the table value is NULL *@code: else { global $cmsFolder; global $templateFolder; $imageTag = "<img src=\"{$hostt}/$cmsFolder/$templateFolder/common/images/folder.png\" alt=\"{$pageRow[$i][1]}\" width=\"16\" height=\"16\"/>"; }*/ } $var .= "\n<li id=\"cms-menu-item{$i}\"><a href=\"" . $rootUri . '/home' . getPagePath($pageRow[$i][0]) . "\" {$opennewtab} ><div class='cms-menuitem'>" . $imageTag . " " . $pageRow[$i][2] . "</div></a>"; $var .= getChildList($pageRow[$i][0], $depth == -1 ? $depth : $depth - 1, $rootUri, $userId, $newdepth, true); $var .= "</li>"; } $var .= "</ul></div>"; if (count($pageRow) == 0) { return ""; } return $var; } }
function generateObjectRow($irn) { $iw = "150"; $sirn = sqlSafe($irn); $query = "SELECT location_name, location_barcode, image_url, title, year, accession_no, medium, barcode FROM objects WHERE irn={$sirn}"; $result = readQuery($query); if ($row = $result->fetch_assoc()) { $info = $row; } else { return null; } $lbarcode = generateBarcode($info['location_barcode']); $lname = $info['location_name']; $title = $info['title']; $year = $info['year']; $creators = getCreators($irn); $acc = $info['accession_no']; $medium = $info['medium']; $measures = getMeasurements($irn); $obarcode = generateBarcode($info['barcode']); $children = getChildren($irn); $html = ''; $html .= "\n<tr>"; //Current Location $html .= "\n<td width=\"16%\">"; $html .= "\n<p>{$lname}</p>"; $html .= "\n{$lbarcode}"; $html .= "\n</td>"; //Object $html .= "\n\t<td width=\"50%\">"; $titlealt = htmlentities($title); $html .= "\n<table class=\"noborder\" summary=\"Alignment Table\">\n\t<tr>"; if (isset($info['image_url'])) { $img = $info['image_url']; $html .= "\n\t\t<td class=\"obj-img\"><img src=\"{$img}\" width=\"{$iw}\" alt=\"{$titlealt}\"/></td>"; } $html .= "\n\t\t<td class=\"obj-txt\">"; $html .= "\n\t\t\t<p><span class=\"obj-title\">{$title},</span> <span class=\"obj-year\">{$year}</span></p>"; foreach ($creators as $key => $c) { $cname = $c['name']; $html .= "\n\t\t\t<p><span class=\"cre-name\">{$cname}</span>"; if (!empty($c['role'])) { $crole = $c['role']; $html .= "<span class=\"cre-role\"> ({$crole})</span>"; } $html .= "</p>"; } $html .= "\n\t\t\t<p class=\"obj-acc\">{$acc}</p>"; $html .= "\n\t\t\t<p class=\"obj-med\">{$medium}</p>"; foreach ($measures as $key => $m) { if (empty($m['type'])) { $type = 'Unknown'; } else { $type = $m['type']; } $html .= "\n\t\t\t<p class=\"obj-measure\">{$type}: "; $first = true; if (!empty($m['height'])) { $first = false; $html .= "H: " . $m['height'] . " in."; } if (!empty($m['width'])) { if (!$first) { $html .= " x"; } $first = false; $html .= " W: " . $m['width'] . " in."; } if (!empty($m['depth'])) { if (!$first) { $html .= " x"; } $html .= " D: " . $m['depth'] . " in."; } $html .= "</p>"; } $html .= "\n\t\t\t{$obarcode}"; $html .= "\n\t\t</td>"; $html .= "</tr></table>"; if (count($children) >= 1) { $html .= "\n\t\t<table summary=\"Children of {$titlealt}\"class=\"obj-parts\">"; $html .= "\n\t\t\t<tr>"; $html .= "\n\t\t\t\t<th colspan=\"1\">Location</th>"; $html .= "\n\t\t\t\t<th>Parts</th>"; $html .= "\n\t\t\t</tr>"; foreach ($children as $key => $c) { $bcode = generateBarcode($c['barcode']); $lbcode = generateBarcode($c['location_barcode']); $title = $c['title']; $accno = $c['accession_no']; $loc = $c['location_name']; $cirn = $c['irn']; $html .= "\n\t\t\t<tr>"; $html .= "\n\t\t\t\t<td >"; $html .= "\n\t\t\t\t\t<p class=\"part-loc\">{$loc}</p>"; $html .= "\n\t\t\t\t\t{$lbcode}"; $html .= "\n\t\t\t\t</td>"; $html .= "\n\t\t\t\t<td><span class=\"part-acc\">{$accno}</span> - <span class=\"part-title\">{$title}</span>"; $html .= "\n\t\t\t\t\t{$bcode}"; $html .= "\n\t\t\t\t</td>"; $html .= "\n\t\t\t</tr>"; } $html .= "\n\t\t</table>"; } $html .= "\n\t</td>"; //Specific Location $html .= "\n\t<td width=\"16%\">"; $html .= "\n\t\t\t<p class=\"specLoc\">Building:<br>"; $html .= "\n\t\t\tRoom / Gallery:<br>"; $html .= "\n\t\t\tBin / Rack / Zone:<br>"; $html .= "\n\t\t\tUnit / Cab. / Case:<br>"; $html .= "\n\t\t\tShlf / Drwr / Rack:<br>"; $html .= "\n\t\t\tOther:<br> </p>"; $html .= "\n\t</td>"; //Audit $html .= "\n\t<td width=\"16%\">"; $html .= "\n\t\t<div class=\"audit\">"; $html .= "\n\t\t\t<p>Moved By:</p>"; $html .= "\n\t\t\t<p>Date:</p>"; $html .= "\n\t\t\t<p>Rec. in EMu By:</p>"; $html .= "\n\t\t\t<p>Date:</p>"; $html .= "\n\t\t</div>"; $html .= "\n\t</td>"; //End $html .= "\n</tr>"; /* $html .= "\n<tr class='pb'>"; $html .= "\n\t<td class='pb'>"; $html .= "\n\t\t<div class='pb'>"; $html .= "\n\t\t</div>"; $html .= "\n\t</td>"; $html .= "\n</tr>"; */ return $html; }