/** * Compiles information to add or edit a module * @param string The current GET/POST option * @param integer The unique id of the record to edit */ function editModule($option, $uid, $client) { global $database, $my, $mainframe; global $mosConfig_absolute_path; $lists = array(); $row = new mosModule($database); // load the row from the db table $row->load((int) $uid); // fail if checked out not by 'me' if ($row->isCheckedOut($my->id)) { mosErrorAlert("The module " . $row->title . " is currently being edited by another administrator"); } $row->content = htmlspecialchars($row->content); if ($uid) { $row->checkout($my->id); } // if a new record we must still prime the mosModule object with a default // position and the order; also add an extra item to the order list to // place the 'new' record in last position if desired if ($uid == 0) { $row->position = 'left'; $row->showtitle = true; //$row->ordering = $l; $row->published = 1; } if ($client == 'admin') { $where = "client_id = 1"; $lists['client_id'] = 1; $path = 'mod1_xml'; } else { $where = "client_id = 0"; $lists['client_id'] = 0; $path = 'mod0_xml'; } $query = "SELECT position, ordering, showtitle, title" . "\n FROM #__modules" . "\n WHERE {$where}" . "\n ORDER BY ordering"; $database->setQuery($query); if (!($orders = $database->loadObjectList())) { echo $database->stderr(); return false; } $query = "SELECT position, description" . "\n FROM #__template_positions" . "\n WHERE position != ''" . "\n ORDER BY position"; $database->setQuery($query); // hard code options for now $positions = $database->loadObjectList(); $orders2 = array(); $pos = array(); foreach ($positions as $position) { $orders2[$position->position] = array(); $pos[] = mosHTML::makeOption($position->position, $position->description); } $l = 0; $r = 0; for ($i = 0, $n = count($orders); $i < $n; $i++) { $ord = 0; if (array_key_exists($orders[$i]->position, $orders2)) { $ord = count(array_keys($orders2[$orders[$i]->position])) + 1; } $orders2[$orders[$i]->position][] = mosHTML::makeOption($ord, $ord . '::' . addslashes($orders[$i]->title)); } // build the html select list $pos_select = 'onchange="changeDynaList(\'ordering\',orders,document.adminForm.position.options[document.adminForm.position.selectedIndex].value, originalPos, originalOrder)"'; $active = $row->position ? $row->position : 'left'; $lists['position'] = mosHTML::selectList($pos, 'position', 'class="inputbox" size="1" ' . $pos_select, 'value', 'text', $active); // get selected pages for $lists['selections'] if ($uid) { $query = "SELECT menuid AS value" . "\n FROM #__modules_menu" . "\n WHERE moduleid = " . (int) $row->id; $database->setQuery($query); $lookup = $database->loadObjectList(); } else { $lookup = array(mosHTML::makeOption(0, 'All')); } if ($row->access == 99 || $row->client_id == 1 || $lists['client_id']) { $lists['access'] = 'Administrator<input type="hidden" name="access" value="99" />'; $lists['showtitle'] = 'N/A <input type="hidden" name="showtitle" value="1" />'; $lists['selections'] = 'N/A'; } else { if ($client == 'admin') { $lists['access'] = 'N/A'; $lists['selections'] = 'N/A'; } else { $lists['access'] = mosAdminMenus::Access($row); $lists['selections'] = mosAdminMenus::MenuLinks($lookup, 1, 1); } $lists['showtitle'] = mosHTML::yesnoRadioList('showtitle', 'class="inputbox"', $row->showtitle); } // build the html select list for published $lists['published'] = mosAdminMenus::Published($row); $row->description = ''; // XML library require_once $mosConfig_absolute_path . '/includes/domit/xml_domit_lite_include.php'; // xml file for module $xmlfile = $mainframe->getPath($path, $row->module); $xmlDoc = new DOMIT_Lite_Document(); $xmlDoc->resolveErrors(true); if ($xmlDoc->loadXML($xmlfile, false, true)) { $root =& $xmlDoc->documentElement; if ($root->getTagName() == 'mosinstall' && $root->getAttribute('type') == 'module') { $element =& $root->getElementsByPath('description', 1); $row->description = $element ? trim($element->getText()) : ''; } } // get params definitions $params = new mosParameters($row->params, $xmlfile, 'module'); HTML_modules::editModule($row, $orders2, $lists, $params, $option); }