| 33 | | */ |
|---|
| 34 | | private function _process_order_form() |
|---|
| 35 | | { |
|---|
| 36 | | // If the navigation order is changed, it will be saved first. After this it is possible |
|---|
| 37 | | // again to organize the folder |
|---|
| 38 | | if ($_POST['f_navorder'] != $this->_topic->parameter('midcom.helper.nav', 'navorder')) |
|---|
| 39 | | { |
|---|
| 40 | | $this->_topic->set_parameter('midcom.helper.nav', 'navorder', $_POST['f_navorder']); |
|---|
| | 33 | * @return boolean Indicating success |
|---|
| | 34 | */ |
|---|
| | 35 | function _process_order_form() |
|---|
| | 36 | { |
|---|
| | 37 | if (isset($_POST['f_navorder'])) |
|---|
| | 38 | { |
|---|
| | 39 | $this->_topic->set_parameter('midcom.helper.nav', 'nav_order', $_POST['f_navorder']); |
|---|
| | 40 | } |
|---|
| | 41 | |
|---|
| | 42 | // Form has been handled if cancel has been pressed |
|---|
| | 43 | if (isset($_POST['f_cancel'])) |
|---|
| | 44 | { |
|---|
| | 45 | $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('midcom.admin.folder'), $_MIDCOM->i18n->get_string('cancelled')); |
|---|
| | 46 | $_MIDCOM->relocate($_MIDCOM->permalinks->create_permalink($this->_topic->guid)); |
|---|
| | 47 | exit; |
|---|
| | 48 | // This will exit |
|---|
| | 49 | } |
|---|
| | 50 | |
|---|
| | 51 | // If the actual score list hasn't been posted, return false |
|---|
| | 52 | if (!isset($_POST['f_submit'])) |
|---|
| | 53 | { |
|---|
| 66 | | if (!$article->update()) |
|---|
| 67 | | { |
|---|
| 68 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 69 | | debug_add("Updating the article with id '{$id}' failed. Reason: ". mgd_errstr(), MIDCOM_LOG_ERROR); |
|---|
| 70 | | debug_pop(); |
|---|
| | 94 | // Store the old-fashioned score as well |
|---|
| | 95 | if (isset($object->score)) |
|---|
| | 96 | { |
|---|
| | 97 | $object->score = $score; |
|---|
| | 98 | } |
|---|
| | 99 | |
|---|
| | 100 | $object->metadata->score = $score; |
|---|
| | 101 | |
|---|
| | 102 | // Show an error message on an update failure |
|---|
| | 103 | if (!$object->update()) |
|---|
| | 104 | { |
|---|
| | 105 | // Some heuristics for the update logging |
|---|
| | 106 | if ( isset($object->title) |
|---|
| | 107 | && $object->title) |
|---|
| | 108 | { |
|---|
| | 109 | $title = $object->title; |
|---|
| | 110 | } |
|---|
| | 111 | elseif (isset($object->extra) |
|---|
| | 112 | && $object->extra) |
|---|
| | 113 | { |
|---|
| | 114 | $title = $object->extra; |
|---|
| | 115 | } |
|---|
| | 116 | elseif (isset($object->name) |
|---|
| | 117 | && $object->name) |
|---|
| | 118 | { |
|---|
| | 119 | $title = $object->name; |
|---|
| | 120 | } |
|---|
| | 121 | else |
|---|
| | 122 | { |
|---|
| | 123 | $title = sprintf("{$object->guid} %s", get_class($object)); |
|---|
| | 124 | } |
|---|
| 86 | | if (array_key_exists('midcom_admin_content_folder_score', $_POST)) |
|---|
| 87 | | { |
|---|
| 88 | | $count = count($_POST['midcom_admin_content_folder_score']); |
|---|
| 89 | | |
|---|
| 90 | | foreach ($_POST['midcom_admin_content_folder_score'] as $key => $id) |
|---|
| 91 | | { |
|---|
| 92 | | $topic = new midcom_db_topic($id); |
|---|
| 93 | | $topic->score = (int) $key; |
|---|
| 94 | | $topic->metadata->score = (int) $count - $key; |
|---|
| 95 | | |
|---|
| 96 | | // Get the original approval status |
|---|
| 97 | | $metadata =& midcom_helper_metadata::retrieve($topic); |
|---|
| 98 | | $approval_status = false; |
|---|
| 99 | | |
|---|
| 100 | | // Get the approval status if metadata object is available |
|---|
| 101 | | if ( is_object($metadata) |
|---|
| 102 | | && $metadata->is_approved()) |
|---|
| 103 | | { |
|---|
| 104 | | $approval_status = true; |
|---|
| 105 | | } |
|---|
| 106 | | |
|---|
| 107 | | if (!$topic->update()) |
|---|
| 108 | | { |
|---|
| 109 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 110 | | debug_add("Updating the topic with id '{$id}' failed. Reason: ". mgd_errstr(), MIDCOM_LOG_ERROR); |
|---|
| 111 | | debug_pop(); |
|---|
| 112 | | |
|---|
| 113 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Saving the order failed, see error level log for details'); |
|---|
| 114 | | // This will exit |
|---|
| 115 | | } |
|---|
| 116 | | |
|---|
| 117 | | // Maintain the approval status - if the object had been approved before |
|---|
| 118 | | // it should still be kept as approved |
|---|
| 119 | | if ($approval_status) |
|---|
| 120 | | { |
|---|
| 121 | | $metadata =& midcom_helper_metadata::retrieve($topic); |
|---|
| 122 | | $metadata->approve(); |
|---|
| 123 | | } |
|---|
| 124 | | } |
|---|
| 125 | | } |
|---|
| 126 | | |
|---|
| 127 | | if (array_key_exists('midcom_admin_content_mixed_score', $_POST)) |
|---|
| 128 | | { |
|---|
| 129 | | $count = count($_POST['midcom_admin_content_mixed_score']); |
|---|
| 130 | | |
|---|
| 131 | | foreach ($_POST['midcom_admin_content_mixed_score'] as $key => $id) |
|---|
| 132 | | { |
|---|
| 133 | | $type = explode('_', $id); |
|---|
| 134 | | if ($type[2] === 'folder') |
|---|
| 135 | | { |
|---|
| 136 | | $object = new midcom_db_topic($type[1]); |
|---|
| 137 | | } |
|---|
| 138 | | else |
|---|
| 139 | | { |
|---|
| 140 | | $object = new midcom_db_article($type[1]); |
|---|
| 141 | | } |
|---|
| 142 | | |
|---|
| 143 | | if (!is_object($object)) |
|---|
| 144 | | { |
|---|
| 145 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 146 | | debug_add("Could not get the {$type[1]} with id '{$id}'. Reason: ". mgd_errstr(), MIDCOM_LOG_ERROR); |
|---|
| 147 | | debug_pop(); |
|---|
| 148 | | |
|---|
| 149 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Saving the order failed, see error level log for details'); |
|---|
| 150 | | } |
|---|
| 151 | | |
|---|
| 152 | | // Get the original approval status |
|---|
| 153 | | $metadata =& midcom_helper_metadata::retrieve($object); |
|---|
| 154 | | $approval_status = false; |
|---|
| 155 | | |
|---|
| 156 | | $object->metadata->score = (int) $count - $key; |
|---|
| 157 | | |
|---|
| 158 | | // Get the approval status if metadata object is available |
|---|
| 159 | | if ( is_object($metadata) |
|---|
| 160 | | && $metadata->is_approved()) |
|---|
| 161 | | { |
|---|
| 162 | | $approval_status = true; |
|---|
| 163 | | } |
|---|
| 164 | | |
|---|
| 165 | | $object->score = (int) $key; |
|---|
| 166 | | |
|---|
| 167 | | if (!$object->update()) |
|---|
| 168 | | { |
|---|
| 169 | | debug_push_class(__CLASS__, __FUNCTION__); |
|---|
| 170 | | debug_add("Updating the {$type[1]} with id '{$id}' failed. Reason: ". mgd_errstr(), MIDCOM_LOG_ERROR); |
|---|
| 171 | | debug_pop(); |
|---|
| 172 | | |
|---|
| 173 | | $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Saving the order failed, see error level log for details'); |
|---|
| 174 | | // This will exit |
|---|
| 175 | | } |
|---|
| 176 | | |
|---|
| 177 | | // Maintain the approval status - if the object had been approved before |
|---|
| 178 | | // it should still be kept as approved |
|---|
| 179 | | if ($approval_status) |
|---|
| 180 | | { |
|---|
| 181 | | $metadata =& midcom_helper_metadata::retrieve($object); |
|---|
| 182 | | $metadata->approve(); |
|---|
| 183 | | } |
|---|
| 184 | | } |
|---|
| 185 | | } |
|---|
| 186 | | |
|---|
| 187 | | return true; |
|---|
| | 141 | if ($success) |
|---|
| | 142 | { |
|---|
| | 143 | $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('midcom.admin.folder'), $_MIDCOM->i18n->get_string('order saved')); |
|---|
| | 144 | $_MIDCOM->relocate($_MIDCOM->permalinks->create_permalink($this->_topic->guid)); |
|---|
| | 145 | exit; |
|---|
| | 146 | // This will exit |
|---|
| | 147 | } |
|---|
| 195 | | // Include Scriptaculous JavaScript library to headers |
|---|
| 196 | | // Scriptaculous/scriptaculous.js |
|---|
| 197 | | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/Pearified/JavaScript/Prototype/prototype.js'); |
|---|
| 198 | | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/Pearified/JavaScript/Scriptaculous/scriptaculous.js'); |
|---|
| | 155 | // Include Scriptaculous JavaScript libraries to headers |
|---|
| | 156 | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/jQuery/jquery.dimensions-1.1.2.js'); |
|---|
| | 157 | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/jQuery/jquery.form-1.0.3.js'); |
|---|
| | 158 | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/jQuery/ui/ui.mouse.js'); |
|---|
| | 159 | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/jQuery/ui/ui.draggable.js'); |
|---|
| | 160 | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/jQuery/ui/ui.droppable.js'); |
|---|
| | 161 | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/jQuery/ui/ui.sortable.js'); |
|---|
| | 162 | $_MIDCOM->add_jsfile(MIDCOM_STATIC_URL.'/midcom.admin.folder/jquery-postfix.js'); |
|---|
| | 163 | |
|---|
| | 164 | // These pages need no caching |
|---|
| | 165 | $_MIDCOM->cache->content->no_cache(); |
|---|
| | 166 | |
|---|
| | 167 | // Custom styles |
|---|
| 271 | | $this->_request_data['sort_order_header'] = $this->_request_data['navorder_list'][$this->_request_data['navorder']]; |
|---|
| 272 | | |
|---|
| 273 | | $qb = midcom_db_topic::new_query_builder(); |
|---|
| 274 | | $qb->add_constraint('up', '=', $this->_topic->id); |
|---|
| 275 | | $qb->add_constraint('metadata.navnoentry', '=', 0); |
|---|
| 276 | | $qb->add_order('metadata.score', 'DESC'); |
|---|
| 277 | | //$qb->add_order('name'); |
|---|
| 278 | | //$qb->add_order('extra'); |
|---|
| 279 | | |
|---|
| 280 | | $this->_request_data['folders'] = $qb->execute(); |
|---|
| 281 | | |
|---|
| 282 | | $qb = midcom_db_article::new_query_builder(); |
|---|
| 283 | | $qb->add_constraint('topic', '=', $this->_topic->id); |
|---|
| 284 | | if (!$this->_config->get('indexinnav')) |
|---|
| 285 | | { |
|---|
| 286 | | $qb->add_constraint('name', '<>', 'index'); |
|---|
| 287 | | } |
|---|
| 288 | | $qb->add_constraint('up', '=', 0); |
|---|
| 289 | | $qb->add_order('metadata.score', 'DESC'); |
|---|
| 290 | | //$qb->add_order('name'); |
|---|
| 291 | | //$qb->add_order('title'); |
|---|
| 292 | | |
|---|
| 293 | | $this->_request_data['pages'] = $qb->execute(); |
|---|
| 294 | | |
|---|
| 295 | | // Show the header element, which allows to change the sorting order |
|---|
| 296 | | // and displays headers for the user |
|---|
| 297 | | midcom_show_style('midcom-admin-show-order-header'); |
|---|
| 298 | | |
|---|
| 299 | | switch ($this->_topic->parameter('midcom.helper.nav', 'navorder')) |
|---|
| 300 | | { |
|---|
| 301 | | // If the sort order is 'Pages first' |
|---|
| 302 | | case MIDCOM_NAVORDER_ARTICLESFIRST: |
|---|
| 303 | | if (count($this->_request_data['pages']) > 1) |
|---|
| 304 | | { |
|---|
| 305 | | midcom_show_style('midcom-admin-show-order-pages'); |
|---|
| 306 | | } |
|---|
| 307 | | |
|---|
| 308 | | if (count($this->_request_data['folders']) > 1) |
|---|
| 309 | | { |
|---|
| 310 | | midcom_show_style('midcom-admin-show-order-folders'); |
|---|
| | 235 | if (!isset($_GET['ajax'])) |
|---|
| | 236 | { |
|---|
| | 237 | midcom_show_style('midcom-admin-folder-order-start'); |
|---|
| | 238 | } |
|---|
| | 239 | |
|---|
| | 240 | // Initialize the midcom_helper_nav or navigation access point |
|---|
| | 241 | $nap = new midcom_helper_nav(); |
|---|
| | 242 | |
|---|
| | 243 | switch ((int) $this->_topic->get_parameter('midcom.helper.nav', 'nav_order')) |
|---|
| | 244 | { |
|---|
| | 245 | case MIDCOM_NAVORDER_DEFAULT: |
|---|
| | 246 | $data['navigation']['nodes'] = array(); |
|---|
| | 247 | $nodes = $nap->list_nodes($this->_topic->id); |
|---|
| | 248 | |
|---|
| | 249 | foreach ($nodes as $id => $node_id) |
|---|
| | 250 | { |
|---|
| | 251 | $node = $nap->get_node($node_id); |
|---|
| | 252 | $node[MIDCOM_NAV_TYPE] = 'node'; |
|---|
| | 253 | $data['navigation']['nodes'][$id] = $node; |
|---|
| 316 | | if (count($this->_request_data['folders']) > 1) |
|---|
| 317 | | { |
|---|
| 318 | | midcom_show_style('midcom-admin-show-order-folders'); |
|---|
| 319 | | } |
|---|
| 320 | | |
|---|
| 321 | | if (count($this->_request_data['pages']) > 1) |
|---|
| 322 | | { |
|---|
| 323 | | midcom_show_style('midcom-admin-show-order-pages'); |
|---|
| | 258 | // Sort the array to have the nodes first |
|---|
| | 259 | $data['navigation'] = array |
|---|
| | 260 | ( |
|---|
| | 261 | 'nodes' => array(), |
|---|
| | 262 | 'leaves' => array(), |
|---|
| | 263 | ); |
|---|
| | 264 | // Fall through |
|---|
| | 265 | |
|---|
| | 266 | case MIDCOM_NAVORDER_ARTICLESFIRST: |
|---|
| | 267 | // Sort the array to have the leaves first |
|---|
| | 268 | |
|---|
| | 269 | if (!isset($data['navigation']['leaves'])) |
|---|
| | 270 | { |
|---|
| | 271 | $data['navigation'] = array |
|---|
| | 272 | ( |
|---|
| | 273 | 'leaves' => array(), |
|---|
| | 274 | 'nodes' => array(), |
|---|
| | 275 | ); |
|---|
| | 276 | } |
|---|
| | 277 | |
|---|
| | 278 | // Get the nodes |
|---|
| | 279 | $nodes = $nap->list_nodes($this->_topic->id); |
|---|
| | 280 | |
|---|
| | 281 | foreach ($nodes as $id => $node_id) |
|---|
| | 282 | { |
|---|
| | 283 | $node = $nap->get_node($node_id); |
|---|
| | 284 | $node[MIDCOM_NAV_TYPE] = 'node'; |
|---|
| | 285 | $data['navigation']['nodes'][$id] = $node; |
|---|
| | 286 | } |
|---|
| | 287 | |
|---|
| | 288 | // Get the leafs |
|---|
| | 289 | $leaves = $nap->list_leaves($this->_topic->id); |
|---|
| | 290 | |
|---|
| | 291 | foreach ($leaves as $id => $leaf_id) |
|---|
| | 292 | { |
|---|
| | 293 | $leaf = $nap->get_leaf($leaf_id); |
|---|
| | 294 | $leaf[MIDCOM_NAV_TYPE] = 'leaf'; |
|---|
| | 295 | $data['navigation']['leaves'][$id] = $leaf; |
|---|
| 329 | | $this->_request_data['mixed'] = array (); |
|---|
| 330 | | |
|---|
| 331 | | foreach ($this->_request_data['folders'] as $topic) |
|---|
| 332 | | { |
|---|
| 333 | | $score = $this->_get_score($topic->score); |
|---|
| 334 | | $this->_request_data['mixed'][$score . '_' . $topic->id . '_folder'] = $topic->extra; |
|---|
| 335 | | } |
|---|
| 336 | | |
|---|
| 337 | | foreach ($this->_request_data['pages'] as $article) |
|---|
| 338 | | { |
|---|
| 339 | | $score = $this->_get_score($article->score); |
|---|
| 340 | | $this->_request_data['mixed'][$score . '_' . $article->id . '_page'] = $article->title; |
|---|
| 341 | | } |
|---|
| 342 | | |
|---|
| 343 | | ksort($this->_request_data['mixed']); |
|---|
| 344 | | |
|---|
| 345 | | midcom_show_style('midcom-admin-show-order-mixed'); |
|---|
| | 300 | default: |
|---|
| | 301 | $data['navigation']['mixed'] = array(); |
|---|
| | 302 | |
|---|
| | 303 | // Get the navigation items |
|---|
| | 304 | $items = $nap->list_child_elements($this->_topic->id); |
|---|
| | 305 | |
|---|
| | 306 | foreach ($items as $id => $item) |
|---|
| | 307 | { |
|---|
| | 308 | if ($item[MIDCOM_NAV_TYPE] === 'node') |
|---|
| | 309 | { |
|---|
| | 310 | $element = $nap->get_node($item[MIDCOM_NAV_ID]); |
|---|
| | 311 | } |
|---|
| | 312 | else |
|---|
| | 313 | { |
|---|
| | 314 | $element = $nap->get_leaf($item[MIDCOM_NAV_ID]); |
|---|
| | 315 | } |
|---|
| | 316 | |
|---|
| | 317 | // Store the type information |
|---|
| | 318 | $element[MIDCOM_NAV_TYPE] = $item[MIDCOM_NAV_TYPE]; |
|---|
| | 319 | |
|---|
| | 320 | $data['navigation']['mixed'][] = $element; |
|---|
| | 321 | } |
|---|
| 347 | | |
|---|
| 348 | | // If the sort order is 'Default component sort order' |
|---|
| 349 | | case MIDCOM_NAVORDER_DEFAULT: |
|---|
| 350 | | default: |
|---|
| 351 | | if (count($this->_request_data['folders']) > 1) |
|---|
| 352 | | { |
|---|
| 353 | | midcom_show_style('midcom-admin-show-order-folders'); |
|---|
| 354 | | } |
|---|
| 355 | | else |
|---|
| 356 | | { |
|---|
| 357 | | midcom_show_style('midcom-admin-show-order-empty'); |
|---|
| 358 | | } |
|---|
| 359 | | |
|---|
| 360 | | midcom_show_style('midcom-admin-show-order-default'); |
|---|
| 361 | | break; |
|---|
| 362 | | |
|---|
| 363 | | } |
|---|
| 364 | | |
|---|
| 365 | | if ( count($this->_request_data['folders']) < 2 |
|---|
| 366 | | && count($this->_request_data['pages']) < 2) |
|---|
| 367 | | { |
|---|
| 368 | | midcom_show_style('midcom-admin-show-order-empty'); |
|---|
| 369 | | } |
|---|
| 370 | | |
|---|
| 371 | | midcom_show_style('midcom-admin-show-order-footer'); |
|---|
| | 323 | } |
|---|
| | 324 | |
|---|
| | 325 | // Loop through each navigation type (node, leaf and mixed) |
|---|
| | 326 | foreach ($data['navigation'] as $key => $array) |
|---|
| | 327 | { |
|---|
| | 328 | $data['navigation_type'] = $key; |
|---|
| | 329 | $data['navigation_items'] = $array; |
|---|
| | 330 | midcom_show_style('midcom-admin-folder-order-type'); |
|---|
| | 331 | } |
|---|
| | 332 | |
|---|
| | 333 | if (!isset($_GET['ajax'])) |
|---|
| | 334 | { |
|---|
| | 335 | midcom_show_style('midcom-admin-folder-order-end'); |
|---|
| | 336 | } |
|---|