/** * Create a hierarchical ordered dropdown of all the content objects in the system for use * in the admin and various modules. If $current or $parent variables are passed, care is taken * to make sure that children which could cause a loop are hidden, in cases of when you're creating * a dropdown for changing a content object's parent. * * @param string $current The currently selected content object. If none is given, we show all items. * @param string $parent The parent of the currently selected content object. If none is given, we show all items. * @param string $name The html name of the dropdown * @param boolean $allowcurrent Overrides the logic if $current and/or $parent are passed. Defaults to false. * @param boolean $use_perms If true, checks authorship permissions on pages and only shows those the current * user has access to. * @param boolean $ignore_current Ignores the value of $current totally by not marking any items as invalid. * @param boolean $allow_all If true, show all items, even if the content object * doesn't have a valid link. Defaults to false. * @return string The html dropdown of the hierarchy */ function CreateHierarchyDropdown($current = '', $parent = '', $name = 'parent_id', $allowcurrent = 0, $use_perms = 0, $ignore_current = 0, $allow_all = false) { $result = ''; $userid = -1; $allcontent =& ContentOperations::GetAllContent(); if ($allcontent !== FALSE && count($allcontent) > 0) { if ($use_perms) { $userid = get_userid(); } if ($userid > 0 && check_permission($userid, 'Manage All Content') || $userid == -1 || $parent == -1) { $result .= '<option value="-1">' . lang('none') . '</option>'; } $curhierarchy = ''; foreach ($allcontent as $one) { $value = $one->Id(); if ($value == $current) { // Grab hierarchy just in case we need to check children // (which will always be after) $curhierarchy = $one->Hierarchy(); if (!$allowcurrent) { // Then jump out. We don't want ourselves in the list. continue; } $value = -1; } // If it doesn't have a valid link... // don't include it. if (!$allow_all && !$one->HasUsableLink()) { continue; } // If it's a child of the current, we don't want to show it as it // could cause a deadlock. if (!$allowcurrent && $curhierarchy != '' && strstr($one->Hierarchy() . '.', $curhierarchy . '.') == $one->Hierarchy() . '.') { continue; } // If we have a valid userid... only include pages where this user // has write access... or is an admin user... or has appropriate permission. if ($userid > 0 && $one->Id() != $parent) { if (!check_permission($userid, 'Manage All Content') && !check_authorship($userid, $one->Id())) { continue; } } // Don't include content types that do not want children either... if (!$one->WantsChildren()) { continue; } $result .= '<option value="' . $value . '"'; // Select current parent if it exists if ($one->Id() == $parent) { $result .= ' selected="selected"'; } if ($value == -1 && $ignore_current == 0) { $result .= '>' . $one->Hierarchy() . '. - ' . $one->Name() . ' (' . lang('invalid') . ')</option>'; } else { $result .= '>' . $one->Hierarchy() . '. - ' . $one->Name() . '</option>'; } } } if (!empty($result)) { $result = '<select name="' . $name . '">' . $result . '</select>'; } return $result; }