Esempio n. 1
0
	/**
	 * Ajax handler for updating the order of a number of tree nodes
	 * $_GET[ID]: An array of node ids in the correct order
	 * $_GET[MovedNodeID]: The node that actually got moved
	 */
	public function ajaxupdatesort() {
		$className = $this->stat('tree_class');
		$counter = 0;
		$js = '';
		$_REQUEST['ajax'] = 1;

		if(is_array($_REQUEST['ID'])) {
			if($_REQUEST['MovedNodeID']==0){ //Sorting root
				$movedNode = DataObject::get($className, "`ParentID`=0");				
			}else{
				$movedNode = DataObject::get_by_id($className, $_REQUEST['MovedNodeID']);
			}
			foreach($_REQUEST['ID'] as $id) {
				if($id == $movedNode->ID) {
					$movedNode->Sort = ++$counter;
					$movedNode->Status = "Saved (update)";
					$movedNode->write();

					$title = Convert::raw2js($movedNode->TreeTitle());
					$js .="$('sitetree').setNodeTitle($movedNode->ID, \"$title\");\n";

				// Nodes that weren't "actually moved" shouldn't be registered as having been edited; do a direct SQL update instead
				} else if(is_numeric($id)) {
					++$counter;
					DB::query("UPDATE `$className` SET `Sort` = $counter WHERE `ID` = '$id'");
				}
			}
			// Virtual pages require selected to be null if the page is the same.
			FormResponse::add(
				"if( $('sitetree').selected && $('sitetree').selected[0]){
					var idx =  $('sitetree').selected[0].getIdx();
					if(idx){
						$('Form_EditForm').getPageFromServer(idx);
					}
				}\n" . $js
			);
			FormResponse::status_message(_t('LeftAndMain.SAVED'), 'good');
		} else {
			FormResponse::error(_t('LeftAndMain.REQUESTERROR',"Error in request"));
		}

		return FormResponse::respond();
	}
Esempio n. 2
0
 /**
  * Ajax handler for updating the order of a number of tree nodes
  * $_GET[ID]: An array of node ids in the correct order
  * $_GET[MovedNodeID]: The node that actually got moved
  */
 public function ajaxupdatesort()
 {
     $className = $this->stat('tree_class');
     $counter = 0;
     $js = '';
     $_REQUEST['ajax'] = 1;
     if (!Permission::check('SITETREE_REORGANISE') && !Permission::check('ADMIN')) {
         FormResponse::status_message(_t('LeftAndMain.CANT_REORGANISE', "You do not have permission to rearange the site tree. Your change was not saved."), "bad");
         return FormResponse::respond();
     }
     if (is_array($_REQUEST['ID'])) {
         if ($_REQUEST['MovedNodeID'] == 0) {
             //Sorting root
             $movedNode = DataObject::get($className, "\"ParentID\"=0");
         } else {
             $movedNode = DataObject::get_by_id($className, $_REQUEST['MovedNodeID']);
         }
         foreach ($_REQUEST['ID'] as $id) {
             if ($id == $movedNode->ID) {
                 $movedNode->Sort = ++$counter;
                 $movedNode->Status = "Saved (update)";
                 $movedNode->write();
                 $title = Convert::raw2js($movedNode->TreeTitle());
                 $js .= "\$('sitetree').setNodeTitle({$movedNode->ID}, \"{$title}\");\n";
                 // Nodes that weren't "actually moved" shouldn't be registered as having been edited; do a direct SQL update instead
             } else {
                 if (is_numeric($id)) {
                     ++$counter;
                     DB::query("UPDATE \"{$className}\" SET \"Sort\" = {$counter} WHERE \"ID\" = '{$id}'");
                 }
             }
         }
         FormResponse::status_message(_t('LeftAndMain.SAVED'), 'good');
     } else {
         FormResponse::error(_t('LeftAndMain.REQUESTERROR', "Error in request"));
     }
     return FormResponse::respond();
 }