Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder elementes in form screen #81

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions modules/formulize/admin/reorder_entry_elements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
###############################################################################
## Formulize - ad hoc form creation and reporting module for XOOPS ##
## Copyright (c) 2010 Freeform Solutions ##
###############################################################################
## This program is free software; you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation; either version 2 of the License, or ##
## (at your option) any later version. ##
## ##
## You may not change or alter any portion of this comment or credits ##
## of supporting developers from this source code or any supporting ##
## source code which is considered copyrighted (c) material of the ##
## original comment or credit authors. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program; if not, write to the Free Software ##
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
###############################################################################
## Author of this file: Freeform Solutions ##
## URL: http://www.freeformsolutions.ca/formulize ##
## Project: Formulize ##
###############################################################################

// This file will re order elements from the entry screen

include_once "../../../mainfile.php";
ob_end_clean();
ob_end_clean(); // in some cases there appears to be two buffers active?! So we must try to end twice.
global $xoopsUser;
global $xoopsDB;

if(!$xoopsUser) {
print "Error: you are not logged in";
return;
}
$gperm_handler = xoops_gethandler('groupperm');
include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";
include_once XOOPS_ROOT_PATH ."/modules/formulize/class/forms.php";
$groups = $xoopsUser->getGroups();
$mid = getFormulizeModId();
$permissionToCheck = "module_admin";
$itemToCheck = $mid;
$moduleToCheck = 1; // system module
if(!$gperm_handler->checkRight($permissionToCheck, $itemToCheck, $groups, $moduleToCheck)) {
print "Error: you do not have permission to save this data";
return;
}


$formulizeForm = new formulizeForm();

//error_log($_POST["ele_id"]." ".$_POST["ele_order"]);
$return=$formulizeForm->reorderElements($_POST["ele_id"],$_POST["ele_order"]);


12 changes: 12 additions & 0 deletions modules/formulize/class/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
include_once XOOPS_ROOT_PATH.'/modules/formulize/include/functions.php';

class formulizeForm extends XoopsObject {

function reorderElements($ele_id,$ele_order){
global $xoopsDB;
//given an element id and element order, reset the element's order in the formulize table

$sql = "UPDATE ".$xoopsDB->prefix('formulize');
$sql .= " SET ele_order=".$ele_order;
$sql .= " WHERE ele_id=".$ele_id;
if ( ! $xoopsDB->queryF($sql) ){
echo( $xoopsDB->error." : error number:".$xoopsDB->errno );
}
}
function checkFormOwnership($id_form,$form_handle){

global $xoopsDB;
Expand Down
91 changes: 89 additions & 2 deletions modules/formulize/include/formdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

//THIS FILE HANDLES THE DISPLAY OF FORMS. FUNCTIONS CAN BE CALLED FROM ANYWHERE (INTENDED FOR PAGEWORKS MODULE)

global $xoopsDB, $xoopsUser;



global $xoopsConfig;
// load the formulize language constants if they haven't been loaded already
if ( file_exists(XOOPS_ROOT_PATH."/modules/formulize/language/".$xoopsConfig['language']."/main.php") ) {
Expand All @@ -46,6 +50,7 @@
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";
include_once XOOPS_ROOT_PATH . "/include/functions.php";


// NEED TO USE OUR OWN VERSION OF THE CLASS, TO GET ELEMENT NAMES IN THE TR TAGS FOR EACH ROW
class formulize_themeForm extends XoopsThemeForm {
/**
Expand All @@ -72,6 +77,15 @@ public function insertBreakFormulize($extra = '', $class= '', $name, $element_ha
* @return string
*/
public function render() {

global $xoopsUser, $gperm_handler;
//Check if user is an admin
$groups = $xoopsUser->getGroups();
$mid = getFormulizeModId();
$permissionToCheck = "module_admin";
$itemToCheck = $mid;
$moduleToCheck = 1; // system module
$isAdmin=$gperm_handler->checkRight($permissionToCheck, $itemToCheck, $groups, $moduleToCheck);
$ele_name = $this->getName();
$ret = "<form id='" . $ele_name
. "' name='" . $ele_name
Expand All @@ -85,6 +99,73 @@ public function render() {
$hidden = '';
list($ret, $hidden) = $this->_drawElements($this->getElements(), $ret, $hidden);
$ret .= "</table>\n$hidden\n</div>\n</form>\n";

#some javascript for updating the elements in the table
#only allow the user to reorganize if user is an admin
if($isAdmin){
$ret .= '<html lang="en">

<script type=\'text/javascript\'>

$("#entryTable tr").hover(
function () {
rowLength=document.getElementById("entryTable").rows.length;
if( $(this).index()<rowLength-2 && $(this).index()>1){
$(this).find("td:last").append("<ul><p style=\"color:blue;\">drag to reorder</p></ul>");
}
},
function () {
$(this).find("td:last").children("ul").remove();
}
);

var fixHelperModified = function(e, tr) {

var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function(index) {
$(this).width($originals.eq(index).width());
});
return $helper;
},
updateIndex = function(e, ui) {
$(\'td.index\', ui.item.parent()).each(function (i) {
$(this).html(i + 1);
});
};
updateTable = function(){
var table = document.getElementById(\'entryTable\');

var rowLength = table.rows.length;
for(var i=2; i<rowLength-2; i+=1){
var row = table.rows[i];
row.setAttribute("rowIndex",i-1);
$.ajax(
{
type:"POST",
url:"admin/reorder_entry_elements.php",
data:{"ele_id":row.getAttribute("rowId"),"ele_order":row.getAttribute("rowIndex")},
success:function(response){
}
});

}
};

$("#entryTable tbody").sortable({

items: \'tr:gt(2):lt(-2)\',
helper: fixHelperModified,
stop: updateIndex,
update: updateTable
}).disableSelection();

</script>

</body>
</html>
';
}
$ret .= $this->renderValidationJS(true);
return $ret;
}
Expand All @@ -103,7 +184,6 @@ public function renderValidationJS( $withtags = true, $skipConditionalCheck = fa
}
return $js;
}

function _drawElements($elements, $ret, $hidden) {
$class ='even';

Expand Down Expand Up @@ -166,6 +246,8 @@ function _drawElements($elements, $ret, $hidden) {
return array($ret, $hidden);
}



// need to check whether the element is a standard element, if if so, add the check for whether its row exists or not
function _drawValidationJS($skipConditionalCheck) {
$fullJs = "";
Expand Down Expand Up @@ -2548,6 +2630,7 @@ function writeHiddenSettings($settings, $form = null) {
// draw in javascript for this form that is relevant to subforms
// $nosave indicates that the user cannot save this entry, so we shouldn't check for formulizechanged
function drawJavascript($nosave) {

static $drawnJavascript = false;
if($drawnJavascript) {
return;
Expand Down Expand Up @@ -2790,9 +2873,11 @@ function drawJavascriptForConditionalElements($conditionalElements, $governingEl

print "
<script type='text/javascript'>

var conditionalHTML = new Array(); // needs to be global!

$(\"#entryTable tbody\").sortable().disableSelection();
$(\"#sort3\").sortable().disableSelection();

jQuery(window).load(function() {

// preload the current state of the HTML for any conditional elements that are currently displayed, so we can compare against what we get back when their conditions change
Expand Down Expand Up @@ -2843,6 +2928,7 @@ function drawJavascriptForConditionalElements($conditionalElements, $governingEl
});
});


function getConditionalHTML(handle) {
partsArray = handle.split('_');
jQuery.get(\"".XOOPS_URL."/modules/formulize/formulize_xhr_responder.php?uid=".$uid."&op=get_element_row_html&elementId=\"+partsArray[3]+\"&entryId=\"+partsArray[2]+\"&fid=\"+partsArray[1], function(data) {
Expand Down Expand Up @@ -2955,6 +3041,7 @@ function ShowHideTableRow(rowSelector, show, speed, callback)




</script>";

}
Expand Down
3 changes: 2 additions & 1 deletion modules/formulize/templates/admin/form_elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<input type="hidden" name="reload_elements" value="">
<input type="hidden" name="aid" value="<{$content.aid}>">
<input type="hidden" name="elementorder" value="">



<div class="accordion-box">
<h2><{$smarty.const._AM_ELE_ADDINGTOFORM}></h2>
<p><{$smarty.const._AM_ELE_CLICKTOADD}></p>
Expand Down
Loading