<?php include_once '../includes/nocache.php'; include_once '../includes/config.php'; include_once '../includes/sanitize.php'; include_once '../includes/helpers.php'; include 'includes/valida-login.php'; include 'includes/meta.php'; require_once 'sllists/SLLists.class.php'; $sortableLists = new SLLists('scriptaculous'); $sortableLists->addList('imageFloatContainer', 'imageFloatOrder', 'div', "overlap:'vertical',constraint:false"); $sortableLists->debug = false; $id_seccion = 'PUBLICIDAD_GARAGE_VERT'; if (isset($_POST['sortableListsSubmitted'])) { $orderArray = SLLists::getOrderArray($_POST['imageFloatOrder'], 'imageFloatContainer'); include_once '../includes/config.php'; foreach ($orderArray as $item) { $campos = array('orden' => $item['order']); $db->update('publicidad', $campos, 'id=' . $item['element']); } redirige_pagina("publicidad_garage.php?err=2&opc=ordenar"); } ?> <link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,700' rel='stylesheet' type='text/css'> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <? $sortableLists->printTopJS(); ?> </head> <body class="bcolor"> <div id="fondo">
// formatting for the list - using a div as the container and images as the list items // $sortableTag = 'img'; // $listFormat = '<div id="sortableList">%s</div>'; // argument is the contents of the list // $listItemFormat = '<img id="item_%s" src="images/%s">'; // two arguments are the idField and the displayField // // No need to change any of the sections below // $sortableLists->addList('sortableList','sortableListOrder',$sortableTag); $sortableLists->debug = false; if (isset($_POST['sortableListsSubmitted'])) { $orderArray = SLLists::getOrderArray($_POST['sortableListOrder'],'sortableList'); foreach($orderArray as $item) { $sql = "UPDATE $dbTable set $orderField=".$item['order']." WHERE $idField=".$item['element']; mysql_query($sql); } } $sql = "SELECT $idField, $displayField, $orderField from $dbTable order by $orderField"; $recordSet = mysql_query($sql); $listArray = array(); while ($record = mysql_fetch_assoc($recordSet)) { $listArray[] = sprintf($listItemFormat,$record[$idField],$record[$displayField]); } mysql_free_result($recordSet); $listHTML = implode("\n",$listArray); ?>
function reorder_process($get) { $userid = get_userid(); $objResponse = new xajaxResponse(); if (check_permission($userid, 'Manage All Content')) { global $gCms; $config =& $gCms->GetConfig(); $db =& $gCms->GetDb(); $contentops =& $gCms->GetContentOperations(); $hm = $contentops->GetAllContentAsHierarchy(false); $hierarchy =& $hm->getRootNode(); require cms_join_path(dirname(dirname(__FILE__)), 'lib', 'sllists', 'SLLists.class.php'); $sortableLists = new SLLists($config["root_url"] . '/lib/scriptaculous'); $listArray = array(); $output = ''; $sortableLists->addList('parent0', 'parent0ListOrder'); $listArray[0] = 'parent0ListOrder'; $output .= '<ul id="parent0" class="sortableList">' . "\n"; foreach ($hierarchy->getChildren(false, true) as $child) { show_h($child, $sortableLists, $listArray, $output); } $output .= '</ul>'; $order_changed = FALSE; foreach ($listArray as $parent_id => $order) { $orderArray = SLLists::getOrderArray($get[$order], 'parent' . $parent_id); foreach ($orderArray as $item) { $node =& $hm->sureGetNodeById($item['element']); if ($node != NULL) { $one =& $node->getContent(); // Only update if order has changed. if ($one->ItemOrder() != $item['order']) { $order_changed = TRUE; $query = 'UPDATE ' . cms_db_prefix() . 'content SET item_order = ? WHERE content_id = ?'; $db->Execute($query, array($item['order'], $item['element'])); } } } } if (TRUE == $order_changed) { global $gCms; $contentops =& $gCms->GetContentOperations(); $contentops->SetAllHierarchyPositions(); $contentops->ClearCache(); } } $objResponse->assign("contentlist", "innerHTML", display_content_list()); return $objResponse; }
</ul> <? $sortableLists->printForm($_SERVER['PHP_SELF'], 'POST', 'Submit', 'button'); ?> <br> <? if(isset($_POST['sortableListsSubmitted'])) { ?> <br><br> The update statements below would update the database with the new order:<br><br> <div style="margin-left:40px;"> <? $orderArray = SLLists::getOrderArray($_POST['categoriesListOrder'],'categories'); foreach($orderArray as $item) { $sql = "UPDATE categories set orderid=".$item['order']." WHERE carid=".$item['element']; echo $sql.'<br>'; } ?> </div> <? } ?> <br><br><br> <h2>Example: Sorting divs</h2> <p>Sorting isn't just for lists. Here we're sorting divs - some of them even have some complex markup inside them including styling, links, tables, and form elements. In order to style elements other than lists, we need to pass a third argument to the addList function that tells scriptaculous which elements should be draggable.</p>