30$MIOLO->page->addScript(
'm_util_validate.js');
34 private $item =
'item';
35 private $tableItem =
'';
36 private $actions =
'';
38 private $table = NULL;
39 private $fields = NULL;
40 private $showButtons =
true;
41 private $hideButtonsOnAdd =
false;
42 private $overflowWidth = NULL;
43 private $overflowType = NULL;
55// get all data from form (the data is cleaned with getAjaxFields from class MTableRawSession)
56// ir uses escape, that convert characters to html entities
57function getFieldValues()
61 for (i=0; i<document.forms[0].elements.length; i++)
63 var field = document.forms[0].elements[i];
65 if ( field.type == 'checkbox' || field.type == 'radio' )
69 temp += field.id + '|' + field.value + '#';
72 else if ( field.className.match(/select m-multitext.*/) )
74 temp += field.id + '|type_select-multiple';
75 for ( var j = 0; j < field.options.length; j++ )
81 temp += escape(field.options[j].value);
85 else if ( field.className.match(/m-combo.*/) )
88 temp += field.id + '|';
92 for ( var j = 0; j < field.options.length; j++ )
94 if (field.options[j].selected)
101 temp += field.options[j].value;
109 else if ( $(field).hasClass('m-multiline-field') && $(field).hasClass('m-editor') )
111 eval('value = CKEDITOR.instances.' + field.id + '.getData();');
112 temp += field.id + '|' + escape(value) + '#';
114 else if ( field.type == 'file' && field.value.length > 0 )
116 var args = new FormData();
117 var file = field.files[0];
118 args.append(field.name, file);
128 success: function(data) {
129 temp += field.id + '|' + data + '#';
131 complete: function(){}
136 temp += field.id + '|' + escape(field.value) + '#';
159 public function __construct($item,
$title, $columns=NULL, $fields=NULL, $opts=array(
'edit',
'remove'), $checkTransaction=NULL)
164 $randomId = (Integer)
$MIOLO->_REQUEST(
'randomid');
165 if ( empty($randomId) )
168 $_REQUEST[
"randomid"] = (Integer) $randomId;
171 parent::__construct($item,
$title,
null, $align);
178 $this->addColumn(_M(
'Actions'),
'left',
true,
'10%',
true,
'');
182if ( document.getElementById(
'$item') )
184 campos =
new Array();
185 campos[0] =
'MSubDetail';
186 campos[1] =
'arrayItemTemp';
187 campos[2] =
'divResponse';
189 for ( i=0; i < 3; i++ )
191 if ( !document.getElementById(campos[i]) )
193 var input = document.createElement(
'input');
194 input.setAttribute(
'type',
'hidden');
195 input.setAttribute(
'id', campos[i]);
196 document.getElementById(
'$item').appendChild(input);
208 return unescape(str.replace(/\+/g,
' '));
216function mioloDoAjax(phpFunction, responseElement)
218 args = getFieldValues();
222 document.getElementById(
'divResponse').value = responseElement;
224 MIOLO_ajaxCall(
'$url ',
'POST', phpFunction, args, ajaxResponse,
'TEXT');
227function ajaxResponse( result )
229 MIOLO_parseAjaxJavascript(result);
230 divResponse = document.getElementById(
'divResponse').value;
231 document.getElementById(divResponse).innerHTML = result;
237 if (strlen(
MIOLO::_REQUEST(
'cpaint_function')) > 0 && strlen($cpaintfunction[0]) > 0)
239 $this->page->addAJAXJsCode($code);
243 $this->page->addJsCode($code);
257 if ( $opts ===
true )
259 $opts = array(
'edit',
'remove');
266 if ( strlen($checkTransaction) )
268 $isAdmin =
$MIOLO->checkAccess($checkTransaction, A_ADMIN, FALSE, TRUE);
272 $allowUpdate =
$MIOLO->checkAccess($checkTransaction, A_UPDATE, FALSE, TRUE);
273 $allowDelete =
$MIOLO->checkAccess($checkTransaction, A_DELETE, FALSE, TRUE);
274 $allowInsert =
$MIOLO->checkAccess($checkTransaction, A_INSERT, FALSE, TRUE);
276 if ( !$allowInsert && !$allowUpdate )
279 $fields = array(
new MDiv(NULL, NULL));
281 elseif ( !$allowInsert )
293 if ( $opts && is_array($opts) )
295 if ( in_array(
'edit', $opts) && $allowUpdate )
297 $this->
addAction(
'editFromTable',
'table-edit.png', $module);
300 if ( in_array(
'duplicate', $opts) && $allowInsert )
302 $this->
addAction(
'duplicateFromTable',
'table-duplicate.png', $module);
305 if ( in_array(
'remove', $opts) && $allowDelete )
307 $this->
addAction(
'removeFromTable',
'table-delete.png', $module);
310 if ( in_array(
'up', $opts) )
312 $this->
addAction(
'upFromTable',
'table-up.png', $module);
315 if ( in_array(
'down', $opts) )
317 $this->
addAction(
'downFromTable',
'table-down.png', $module);
320 if ( in_array(
'noButtons', $opts) )
322 $this->showButtons =
false;
325 if ( in_array(
'updateButton', $opts) )
329 if ( in_array(
'hideButtonsOnAdd', $opts) )
341 $this->updateButton = $show;
350 $this->hideButtonsOnAdd = $hide;
355 $this->page->addJsCode(
"document.getElementById('divButtons').style.display = 'none';");
365 $session =
new MSession(
'CLASSNAME');
366 $object = $session->getValue($item);
368 $session->setValue($item, $object);
377 $session =
new MSession(
'CLASSNAME');
379 $object = $session->getValue($item);
381 return $object->$var;
398 $this->showButtons = $showButtons;
403 return $this->showButtons();
414 $this->overflowWidth = $width;
415 $this->overflowType = $type;
420 if ( is_array($field) )
422 foreach ( $field as
$value )
427 elseif ( $field instanceof
MDiv )
435 elseif ( $field->name )
437 $this->namesArray[] = $field->name;
439 return $this->namesArray;
449 foreach ( (array) $fields as $field )
453 $this->defaultValueFields[] = $dvField =
new MTextField(
"MSubDetail_defaultValue_$field->id", $field->checked ? $field->value : NULL);
456 elseif ( $field instanceof
MDiv )
464 elseif ( $field instanceof
MControl && strlen($field->id) )
466 $this->defaultValueFields[] = $dvField =
new MTextField(
"MSubDetail_defaultValue_$field->id", $field->value);
467 $dvField->addBoxStyle(
'display',
'none');
477 $fields = array_merge($fields, $this->defaultValueFields);
479 $this->fields = $fields;
481 $container->width =
'100%';
491 if ( $columns && is_array($columns) )
493 foreach ( $columns as $line => $info )
495 if ( $info->visible ==
true )
497 $titles[] = $info->title;
499 $temp->align = $info->align;
500 $temp->title = $info->title;
501 $temp->width = $info->width;
502 $temp->visible = $info->visible;
503 $temp->options = $info->options;
504 $temp->replace = $info->replace;
505 $tempColumns[] = $temp;
513 private function addColumn(
$title, $align=
'left', $nowrap=
'notImplemented', $width = NULL,
$visible = TRUE, $options = NULL, $order =
'notImplemented', $filter=
'notImplemented')
533 foreach ( (array) $fields as $field )
539 elseif ( $field instanceof
MDiv )
543 elseif ( is_object($field) && !$field->validator )
549 if ( $validator->mask )
551 $field->addAttribute(
'onkeypress',
"return MUtil_Validate_Mask('$validator->mask', event)");
552 $field->addAttribute(
'onkeyup',
"MUtil_Apply_Mask('$field->name', '$validator->mask', event)");
566 if ( is_null($validators) )
574 $this->gValidator->setValidators($validators);
575 $valids = $this->gValidator->transformToStdClasses();
617 $fieldValidator = NULL;
619 foreach ( $validators as $validator )
621 if ( $validator && $validator->field ==
$name )
623 $fieldValidator = $validator;
628 return $fieldValidator;
631 public function addAction($phpFunction, $img, $imgModule)
635 $action->event =
"AddTableResult" . $this->item;
636 $action->jsFunction =
"AddTableResult" . $this->item;
637 $action->phpFunction = $phpFunction;
639 $action->imgModule = $imgModule;
641 $actions[$phpFunction] =
$action;
649 $url = str_replace(
'&',
'&',
$MIOLO->getCurrentURL());
667 foreach ( $actions as $line => $info )
671 $tempString =
"arrayItem|$i#sessionItem|$item#";
672 $link =
'javascript:document.getElementById(\'MSubDetail\').value=\'' . $item .
'\';document.getElementById(\
'arrayItemTemp\').value=\'' . $i .
'\';mioloDoAjax(\
'' . $info->phpFunction .
'\')
';
673 $linkImg = new MImageLink("link$i", null, $link, $MIOLO->getUI()->getImageTheme($MIOLO->getConf('theme.main
'), $info->img));
674 $result .= $linkImg->generate();
684 public static function getDataStatic($item = NULL)
686 $MIOLO = MIOLO::getInstance();
687 $cpaintArgument = SdAjaxFields($MIOLO->_REQUEST("cpaint_argument"));
688 $randomid = SAGU::NVL($cpaintArgument->randomid, $MIOLO->_REQUEST("randomid"));
690 $itens = $_SESSION['
MSubDetail' . $randomid][$item];
693 $itens = $_SESSION['MSubDetail' . $randomid][$item][0]; //bug??/
695 unset($_SESSION['MSubDetail' . $randomid][$item]); //clearData
696 // rewrite the session with correct arrayItem values
697 unset($itens['event']);
701 foreach ( $itens as $line )
703 $line->arrayItem = $x;
705 $_SESSION['MSubDetail' . $randomid][$item][] = $line;
709 return $_SESSION['MSubDetail' . $randomid][$item];
717 public static function getDataItem($arrayItem, $itemForce=NULL)
719 $MIOLO = MIOLO::getInstance();
720 $cpaintArgument = SdAjaxFields($MIOLO->_REQUEST("cpaint_argument"));
721 $randomid = SAGU::NVL($MIOLO->_REQUEST("randomid"), $cpaintArgument->randomid);
725 $itens = $_SESSION['
MSubDetail' . $randomid][$item];
729 foreach ( $itens as $line => $info )
731 if ( $info->arrayItem == $arrayItem )
745 public static function defineData($arrayItem, $obj, $item=NULL)
747 $MIOLO = MIOLO::getInstance();
748 $randomid = SAGU::NVL($MIOLO->_REQUEST("randomid"), $obj->randomid);
750 $_SESSION['
MSubDetail' . $randomid][$item][$arrayItem] = $obj;
757 public static function addDataStatic($data, $itemForce = NULL)
759 $MIOLO = MIOLO::getInstance();
760 $cpaintArgument = SdAjaxFields($MIOLO->_REQUEST("cpaint_argument"));
761 $randomid = SAGU::NVL($MIOLO->_REQUEST("randomid"), $cpaintArgument->randomid, $data->randomid);
770 if ( is_array($data) )
772 foreach ( $data as $line => $info )
774 MSubDetail::addData($info, $item);
779 $_SESSION['
MSubDetail' . $randomid][$item][] = $data;
790 public static function setDataStatic($data, $itemForce=NULL)
792 if (!strlen($itemForce) > 0)
794 MIOLO::getInstance()->error("Erro de código fonte! O id da MSubDetail não foi informado!");
797 MSubDetail::clearData($itemForce);
798 MSubDetail::addData($data, $itemForce);
799 MSubDetail::getData($itemForce);
802 public function setDataThis($data)
804 self::setDataStatic($data, $this->getName());
807 public function getDataThis($subDetail = null)
811 $subDetail = $this->getName();
813 return self::getDataStatic($subDetail);
816 public function clearDataThis()
818 self::clearDataStatic($this->getName());
821 public function addDataThis($data)
823 self::addDataStatic($data, $this->getName());
826 public function __call($name, $arguments)
828 if ($name == 'setData
')
830 $this->setDataThis($arguments[0]);
832 else if ($name == 'clearData
')
834 $this->clearDataThis();
836 else if ($name == 'addData
')
838 $this->addDataThis($arguments[0]);
840 else if ($name == 'getData
')
842 return $this->getDataThis($arguments[0]);
846 public static function __callStatic($name, $arguments)
848 if ($name == 'setData
')
850 self::setDataStatic($arguments[0], $arguments[1]);
852 else if ($name == 'clearData
')
854 self::clearDataStatic($arguments[0]);
856 else if ($name == 'addData
')
858 self::addDataStatic($arguments[0], $arguments[1]);
860 else if ($name == 'getData
')
862 return self::getDataStatic($arguments[0]);
866 public static function clearDataStatic($itemForce=NULL)
868 $MIOLO = MIOLO::getInstance();
869 $cpaintArgument = SdAjaxFields($MIOLO->_REQUEST("cpaint_argument"));
870 $randomid = SAGU::NVL($MIOLO->_REQUEST("randomid"), $cpaintArgument->randomid);
877 unset($_SESSION['MSubDetail' . $randomid][$item]);
884 public function removeData($arrayItem)
886 $MIOLO = MIOLO::getInstance();
887 $cpaintArgument = SdAjaxFields($MIOLO->_REQUEST("cpaint_argument"));
888 $randomid = SAGU::NVL($MIOLO->_REQUEST("randomid"), $cpaintArgument->randomid);
889 unset($_SESSION['
MSubDetail' . $randomid][$this->item][$arrayItem]);
892 public function generateRequiredLabels($requireds, $fields=NULL)
896 foreach ( $this->fields as $field )
898 if ( $field instanceof MContainer )
900 $this->generateRequiredLabels($requireds, $field->getControls());
904 if ( in_array($field->id, $requireds) )
906 $label = new MFieldLabel($field->id, $field->label);
907 $label->setClass(MControl::CLASS_CAPTION_REQUIRED);
908 $field->label = $label->generate();
914 foreach ( $fields as $field )
916 if ( in_array($field->id, $requireds) )
918 $label = new MFieldLabel($field->id, $field->label);
919 $label->setClass(MControl::CLASS_CAPTION);
920 $label->setClass(MControl::CLASS_CAPTION_REQUIRED);
921 $field->label = $label->generate();
927 public function generate($doNothing=false, $itemForce = NULL, $isStaticCall = false)
929 $MIOLO = MIOLO::getInstance();
930 $url = str_replace('&
', '&
', $MIOLO->getCurrentURL());
931 $MIOLO->getRequiredJS4Ajax();
933 // add a '*
' to required labels
934 if ( $this && !$isStaticCall )
936 $validators = MSubDetail::getValidators($this->item);
938 $requireds = array();
939 if ( is_array($validators) )
941 foreach ( $validators as $validator )
943 if ( $validator->type == 'required
' )
945 $requireds[] = $validator->field;
950 $this->generateRequiredLabels($requireds);
953 if ( $this && !$isStaticCall )
966 $jsGetFieldValues = self::jsGetFieldValues();
972// Converts + => and make unescape (to receive data from server...
977 return unescape(str.replace(/\+/g, ' '));
984function mioloDoAjax(phpFunction, responseElement)
986 args = getFieldValues();
989 document.getElementById('divResponse
').value = responseElement;
991 MIOLO_ajaxCall('$url', 'POST
', phpFunction, args, ajaxResponse, 'TEXT
');
994function ajaxResponse( result )
996 MIOLO_parseAjaxJavascript(result);
997 divResponse = document.getElementById('divResponse
').value;
998 document.getElementById(divResponse).innerHTML = result;
1006 $titles = MSubDetail::getSessionValue('titles
', $item);
1007 $actions = MSubDetail::getSessionValue('actions
', $item);
1008 $columns = MSubDetail::getSessionValue('columns
', $item);
1012 $titles = array_merge(array( _M('Actions
') ), $titles);
1015 $temp->align = 'left
';
1016 $temp->title = _M('Actions
');
1018 $temp->visible = true;
1019 $temp->options = '';
1021 $columns = array_filter($columns);
1022 $columns = array_merge(array( $temp ), $columns); //limpa
1025 $itens = self::getData($item);
1027 $table = new MTableRaw('', array(), $titles);
1028 $table->setAlternate(true);
1029 $table->addAttribute('width
', '100%
');
1030 $table->addBoxStyle('width
', '100%
');
1031 $table->addStyle('width
', '100%
');
1032 $table->addAttribute("style", "width:100%");
1033 $table->addAttribute("cellspacing", "0");
1034 $table->setCellAttribute(0, 0, "width", '5%
');
1036 if ( $this && !$isStaticCall )
1038 if ( $this->showButtons )
1040 $addTitle = _M('Add
');
1041 if ( $this->updateButton )
1043 $js = "document.getElementById( 'MSubDetail' ).value = '$item
';
1044 mioloDoAjax( 'forceAddToTable
' )";
1045 $buttons[] = new MButton('addData
' . $item, $addTitle, $js);
1046 $js = "document.getElementById( 'MSubDetail' ).value = '$item
';
1048 $buttons[] = new MButton('updateData
' . $item, _M('Update
'), $js);
1053 $buttons[] = new MButton('addData
' . $item, $addTitle, $js);
1055 $js = "document.getElementById('MSubDetail').value = '$item
'; mioloDoAjax( 'clearTableFields'); document.getElementById('addData$item
').innerHTML = '$addTitle
'";
1056 $buttons[] = new MButton('clearData
' . $item, _M('Clear
'), $js);
1057 $divButtons = new MDIV('divButtons
', $buttons);
1058 $divButtons->addBoxStyle('width
', '100%
');
1059 $divButtons->addBoxStyle('text-align
', 'center
');
1061 $this->addControl($divButtons);
1069 foreach ( $itens as $i => $info )
1071 if ( !$info->removeData )
1073 unset($encodedInfo);
1074 foreach ( $info as $l => $i )
1076 if ( is_string($i) )
1078 $encodedInfo->$l = urlencode($i);
1079 $encodedInfo->$l = str_replace("\n", '\n
', $encodedInfo->$l);
1083 $encodedInfo->$l = $i;
1091 $actions[$i] = self::generateActionString($i, $item);
1092 $args[] = $actions[$info->arrayItem];
1093 $table->setCellAttribute($i, 0, "align", 'left
');
1096 foreach ( $columns as $line => $column )
1098 if ( $column->visible == true )
1100 if ( $column->options )
1102 $opt = $column->options;
1104 if ( $column->replace )
1106 $args[] = $column->replace[$info->$opt];
1108 elseif ( strpos($info->$opt, 'type_select-multiple
') !== false )
1110 $value = substr($info->$opt, strlen('type_select-multiple
'));
1111 $itens[$i]->$opt = explode('@
', $value);
1112 $args[] = str_replace('@
', '<br/>
', $value);
1116 $args[] = $info->$opt;
1119 if ( $column->align )
1121 $table->setCellAttribute($tablePos, $line, 'align
', $column->align);
1123 if ( $column->width )
1125 $table->setCellAttribute($tablePos, $line, 'width
', $column->width);
1130 $table->setCellAttribute($i, $line, 'id', 'MTableRow-
' . $i . '-
' . $line);
1133 $tableData[] = $args;
1139 $table->array = $tableData;
1140 $temp = $table->generate();
1142 $tempData = self::getData($item);
1145 foreach ( $tempData as $line => $info )
1149 foreach ( $columns as $l => $i )
1151 $options = $i->options;
1154 if ( strpos($info->$options, 'type_select-multiple
') !== false )
1156 $value = implode('@
', $info->$options);
1157 $stringTemp .= empty($value) ? "$options=$value&" : "$options=&";
1161 $stringTemp .= $options . '=
' . urlencode($info->$options) . '&
';
1166 $tempField = new MHiddenField(self::HIDDEN_FIELD_PREFIX_NAME . "_{$item}[]", $stringTemp);
1168 $temp .= $tempField->generate();
1172 if ( !$itemForce && !$isStaticCall )
1174 $div = new MDiv('div
' . $item, $temp);
1176 if ( $this->overflowWidth )
1178 $div->addBoxStyle('overflow-x
', $this->overflowType);
1179 $div->addBoxStyle('width
', $this->overflowWidth . 'px
');
1183 $div->addBoxStyle('width
', '100%
');
1185 $this->controls->add($div);
1186 return parent::generate();
1200 public function update($data = NULL, $itemForce)
1202 $MIOLO = MIOLO::getInstance();
1203 MSubDetail::setData($data, $itemForce);
1204 $subClass = new MSubDetail(rand(), rand());
1205 $generate = $subClass->generate(false, $itemForce, true);
1206 SdsetResponse($generate, 'div
' . $itemForce);
1209 public function checkRemovedItem($field, $line)
1211 $MIOLO = MIOLO::getInstance();
1212 $cpaintArgument = SdAjaxFields($MIOLO->_REQUEST("cpaint_argument"));
1213 $randomid = SAGU::NVL($MIOLO->_REQUEST("randomid"), $cpaintArgument->randomid);
1215 return (isset($_SESSION['MSubDetail' . $randomid][$field][$line]->removeData) && $_SESSION['MSubDetail' . $randomid][$field][$line]->removeData == 1);
1218 public function prepareArgs($formData)
1222 foreach ( $formData as $index => $fullValue )
1224 if ( preg_match('/
'.self::HIDDEN_FIELD_PREFIX_NAME . "_/", $index) )
1226 $fieldIndex = str_replace(self::HIDDEN_FIELD_PREFIX_NAME . "_", "", $index);
1228 if ( !is_array($fullValue) )
1233 foreach ( $fullValue as $x => $content )
1235 $values = explode("&", urldecode($content));
1237 if ( !is_array($values) )
1242 foreach ( $values as $fieldContent )
1244 list($fieldName, $fieldValue) = explode("=", $fieldContent);
1246 if ( !strlen($fieldName) )
1250 $fieldValue = strlen($fieldValue) ? $fieldValue : null;
1252 if ( !MSubDetail::checkRemovedItem($fieldIndex, $x) )
1254 eval("\$f->{$fieldIndex}[{$x}]->{$fieldName} = \$fieldValue;");
1261 $f->$index = $fullValue;
1268 function sumFields($fields, $float=false)
1270 $MIOLO = MIOLO::getInstance();
1271 $cpaintArgument = SdAjaxFields($MIOLO->_REQUEST("cpaint_argument"));
1272 $randomid = SAGU::NVL($MIOLO->_REQUEST("randomid"), $cpaintArgument->randomid);
1274 if ( is_array($fields) )
1276 $_SESSION['MSubDetail' . $randomid]['field_
' . $this->item] = $fields;
1278 $_SESSION['MSubDetail' . $randomid]['type_
' . $this->item] = $float;
1282 public function addActionEvent($action, $function, $class = null)
1284 $_SESSION[$this->item]->event[$action]->function = $function;
1285 $_SESSION[$this->item]->event[$action]->class = $class;
1289 public static function parseMultiTextValue($value)
1291 $codeValue = array();
1292 $data = explode('<br/>
', $value);
1294 foreach ( (array) $data as $line )
1296 $string = trim($line, '[]
');
1297 $codeValue[] = explode('] [
', $string);
1303 public static function jsGetFieldValues()
1306 if ( strpos(MIOLO::getInstance()->getTheme()->id, "sbootstrap") === false )
1308 $ckEditorScript = "eval('value = CKEDITOR.instances.
' + field.id + '.getData();
');";
1312 $ckEditorScript = "eval('value = ck_editors.get(\
"' + field.id + '\").getData();');";
1316 // get all data from form (the data is cleaned with getAjaxFields from class MTableRawSession)
1317 // ir uses escape, that convert characters to html entities
1318 function getFieldValues()
1322 for (i=0; i<document.forms[0].elements.length; i++)
1324 var field = document.forms[0].elements[i];
1326 if ( field.type == 'checkbox' || field.type == 'radio' )
1328 if ( field.checked )
1330 temp += field.id + '|' + field.value + '#';
1333 else if ( field.className.match(/select m-multitext.*/) )
1335 temp += field.id + '|type_select-multiple';
1336 for ( var j = 0; j < field.options.length; j++ )
1342 temp += escape(field.options[j].value);
1346 else if ( field.className.match(/m-combo.*/) )
1348 var selecionou=false;
1349 temp += field.id + '|';
1353 for ( var j = 0; j < field.options.length; j++ )
1355 if (field.options[j].selected)
1362 temp += field.options[j].value;
1370 else if ( $(field).hasClass('m-multiline-field') && $(field).hasClass('m-editor') )
1373 temp += field.id + '|' + escape(value) + '#';
1375 else if ( field.type == 'file' && field.value.length > 0 )
1377 var args = new FormData();
1378 var file = field.files[0];
1379 args.append(field.name, file);
1389 success: function(data) {
1390 temp += field.id + '|' + data + '#';
1392 complete: function(){}
1397 temp += field.id + '|' + escape(field.value) + '#';
1412 $randomid = SAGU::NVL(
$MIOLO->_REQUEST(
"randomid"), $data->randomid);
1413 $object = $data->MSubDetail;
1414 $_SESSION[
'MSubDetail' . $randomid][$object][$data->arrayItemTemp]->removeData =
true;
1416 SdsetResponse($subClass->generate(
false, $object,
true),
'div' . $object,
"document.getElementById('arrayItemTemp').value = '';");
1421 $args->arrayItemTemp =
null;
1429 $randomid = SAGU::NVL(
$MIOLO->_REQUEST(
"randomid"), $data->randomid);
1431 if ( $_SESSION[
'MSubDetail' . $randomid][
'type_' . $data->MSubDetail] ==
'TRUE' )
1442 $_errors =
$gValidator->validate($data, $validators);
1445 $errors = ($errors) ? array_merge($errors, $_errors) : $_errors;
1450 $temp.=
'<span style="color: red;">';
1451 $temp.=
'<b>' . _M(
'The following errors were found') .
':</b>';
1453 foreach ( $errors as
$value )
1455 $temp.=
'<li>' .
$value .
'</li>';
1464 if ( substr(
$value, 0, strlen(
'type_select-multiple')) ==
'type_select-multiple' )
1466 $multiples[
$id] = str_replace(
'@',
'<br/>', substr(
$value, strlen(
'type_select-multiple')));
1470 if ( !empty($multiples) )
1478 if ( $data->arrayItemTemp || $data->arrayItemTemp ===
'0' )
1484 MSubDetail::addData($data, $data->MSubDetail);
1489 foreach ( $fieldNames as
$value )
1492var element = document.getElementById(
'{$value}');
1493var defaultValue =
'';
1494var defaultValueField = document.getElementById(
'MSubDetail_defaultValue_{$value}');
1496if ( defaultValueField )
1498 defaultValue = defaultValueField.value;
1501if ( element &&
'{$value}'.substr(0, 24) !=
'MSubDetail_defaultValue_' )
1503 if ( element.type ==
'checkbox' || element.type ==
'radio' )
1505 if ( defaultValueField )
1507 element.checked = defaultValueField.value !=
'';
1511 element.checked =
false;
1514 else if ( element.type !=
'hidden' && element.className !=
'm-readonly' )
1516 if ( element.className ==
'select m-multitext' )
1518 element.innerHTML = defaultValue;
1520 else if ( $(element).hasClass(
'm-multiline-field') && $(element).hasClass(
'm-editor') )
1527 eval(
'value = CKEDITOR.instances.' + element.id +
'.setData("");');
1533 eval(
'value = ck_editors.get(\"' + element.id +
'\").setData("");');
1538 element.value = defaultValue;
1540 else if ( element.tagName ==
'SELECT' && defaultValue ==
'' && element.options && element.options[0] )
1542 element.value = element.options[0].value;
1544 else if ( $(element).hasClass(
"m-multi-select") )
1546 element.value = defaultValue;
1550 element.value = defaultValue;
1553 if ( $(
'#'+$(element).prop(
'name')+
"Description").length > 0 )
1555 $(
'#'+$(element).prop(
'name')+
"Description").val(element.value);
1559 if ( $(
'#'+$(element).prop(
'name')+
"user").length > 0 )
1561 $(
'#'+$(element).prop(
'name')+
"user").val(element.value);
1567if ( document.getElementById(
'{$value}_sel') )
1569 document.getElementById(
'{$value}_sel').value = defaultValue;
1573 $script .=
"document.getElementById('arrayItemTemp').value='';";
1574 $addTitle = _M(
'Add');
1575 $script .=
"document.getElementById('addData{$data->MSubDetail}').innerHTML = '$addTitle';";
1577 if ( $hideButtonsOnAdd )
1579 $script .=
"document.getElementById('divButtons').style.display = 'none';";
1585 $temp .= $subClass->generate(
false, $data->MSubDetail,
true);
1598 if ( is_array($fieldNames) )
1600 foreach ( $fieldNames as $line => $info )
1604 $ckEditorScript =
"value = CKEDITOR.instances.$info.setData(\"\")";
1608 $ckEditorScript =
"value = ck_editors.get(\"$info\").setData(\"\")";
1612var element = document.getElementById(
'{$info}');
1614if( element.type !=
'hidden' &&
1615 element.className !=
'm-readonly' &&
1616 !$(element).hasClass(
'm-tag-select') &&
1617 (!$(element).hasClass(
'm-combo') && !$(element).attr(
'multiple') ) &&
1618 element.type !=
'checkbox' &&
1619 element.type !=
'radio' )
1623 if ( $(element).hasClass(
'm-multiline-field') && $(element).hasClass(
'm-editor') )
1625 eval(
'$ckEditorScript');
1629 if ( $(
'#'+$(element).prop(
'name')+
"Description").length > 0 )
1631 $(
'#'+$(element).prop(
'name')+
"Description").val(
'');
1635 if ( $(
'#'+$(element).prop(
'name')+
"user").length > 0 )
1637 $(
'#'+$(element).prop(
'name')+
"user").val(
'');
1641else if ( $(element).hasClass(
"m-multi-select") )
1645else if ($(element).hasClass(
'm-tag-select'))
1647 $(element).val(
'').change();
1649else if ( element.className ==
'select m-multitext' )
1651 element.innerHTML =
'';
1657 if( document.getElementById('{$info}_sel') )
1659 document.getElementById('{$info}_sel').value = '';
1664 $temp .=
"document.getElementById('arrayItemTemp').value='';";
1668 $temp .=
"document.getElementById('divButtons').style.display = 'none';";
1672 SdsetResponse($subClass->generate(
false, $args->MSubDetail,
true),
'div' . $args->MSubDetail, $temp);
1677 $object = $data->MSubDetail;
1678 $data->sessionItem = $data->MSubDetail;
1679 $nivel = $data->arrayItem;
1682 $nivel = $data->arrayItemTemp;
1694 SdsetResponse($subClass->generate(
false, $object,
true),
'div' . $data->MSubDetail);
1699 $object = $data->MSubDetail;
1700 $data->sessionItem = $data->MSubDetail;
1701 $nivel = $data->arrayItem;
1704 $nivel = $data->arrayItemTemp;
1706 $item = MSubDetail::getData($object);
1707 if ( $nivel < count($item) - 1 )
1716 SdsetResponse($subClass->generate(
false, $object,
true),
'div' . $data->MSubDetail);
1721 $multiples = array();
1723 foreach ( $args as
$id => $a )
1725 if ( $a ==
'type_select-multiple' )
1728 $url = $args->{
"MSubDetail_personellData[]"};
1730 $data = explode(
'&',
$url);
1732 foreach ( $data as $param )
1734 if ( strpos($param,
$id) !==
false )
1736 list($param,
$value) = explode(
'=', $param);
1763 if ( is_array($fieldNames) )
1766 foreach ( $fieldNames as $line => $info )
1768 $value = $values->$info;
1769 $value = str_replace(
"\n",
'\n', $value);
1770 $value = str_replace(
"\r",
'\r', $value);
1771 $value = str_replace(
"'",
"\'", $value);
1772 $value = str_replace(
'"',
'\"', $value);
1774 if ( is_array($value) )
1776 $value = implode(
'<br/>', $value);
1781 $ckEditorScript =
"var editor = CKEDITOR.instances.' + field.id + ';";
1785 $ckEditorScript =
"var editor = ck_editors.get(\"' + field.id + '\");";
1789function inArray(needle, haystack) {
1790 var length = haystack.length;
1791 for(var i = 0; i < length; i++) {
1792 if(haystack[i] == needle)
return true;
1797var field = document.getElementById(
'$info');
1803 if ( $(field).hasClass(
'm-tag-select') )
1805 $(field).val(
'$value').change();
1807 else if ( field.type ==
'checkbox' )
1809 field.checked = field.value ==
'$value';
1811 else if ( field.type ==
'radio' )
1813 var radios = document.getElementsByName(
'$info');
1815 for ( i = 0; i < radios.length; i++ )
1817 radios[i].checked = radios[i].value ==
'$value';
1820 else if ( $(field).hasClass(
'm-multiline-field') && $(field).hasClass(
'm-editor') )
1822 eval(
'$ckEditorScript');
1823 editor.setData(
'$value');
1824 field.value =
'$value';
1826 else if ( field.className ==
'm-combo' )
1828 var v =
'$value'.split(
',');
1829 for ( var j = 0; j < field.options.length; j++ )
1831 if (inArray(field.options[j].value, v) )
1833 field.options[j].selected =
true;
1837 field.options[j].selected =
false;
1842 else if ( field.className ==
'select m-multitext' )
1844 var v =
'$value'.split(
'<br/>');
1846 field.innerHTML =
'';
1847 for ( i=0; i<v.length; i++)
1854 option = document.createElement(
'option');
1855 option.value = v[i];
1856 option.innerHTML = v[i];
1858 field.appendChild(option);
1864 field.value =
'$value';
1867 if ( $(
'#'+$(field).prop(
'name')+
"Description").length > 0 )
1873 if ( $(
'#'+$(field).prop(
'name')+
"user").length > 0 )
1875 $(
'#'+$(field).prop(
'name')+
"user").val(field.value);
1884for (i=0; i < 10; i++)
1886 radio = document.getElementById(
'{$info}_' + i);
1887 if ( radio && radio.value ==
'{$value}' )
1889 radio.checked =
true;
1892if( document.getElementById(
'{$info}_sel') )
1894 document.getElementById(
'{$info}_sel').value=
'{$value}';
1898 if ( !$updateButton )
1900 $update = _M(
'Update');
1901 $temp .=
"document.getElementById('addData$args->MSubDetail').innerHTML = '$update';\n";
1903 if ( $hideButtonsOnAdd )
1905 $temp .=
"document.getElementById('divButtons').style.display = 'block';\n";
1908 SdsetResponse($subClass->generate(
false, $object,
true),
'div' . $object, $temp);
1913 SdsetResponse($subClass->generate(
false, $args->MSubDetail,
true),
'div' . $args->MSubDetail, $temp);
1922 if ( is_array($fieldNames) )
1925 foreach ( $fieldNames as $line => $info )
1927 $value = $values->$info;
1928 $value = str_replace(
"\n",
'\n', $value);
1929 $value = str_replace(
"\r",
'\r', $value);
1930 $value = str_replace(
"'",
"\'", $value);
1931 $value = str_replace(
'"',
'\"', $value);
1933 if ( !empty($multiples) && $multiples[$info] )
1935 $value = $multiples[$info];
1940 $ckEditorScript =
"var editor = CKEDITOR.instances.' + field.id + ';";
1944 $ckEditorScript =
"var editor = ck_editors.get(\"' + field.id + '\");";
1950var field = document.getElementById(
'$info');
1952if ( field.type ==
'checkbox' )
1954 field.checked = field.value ==
'$value';
1956else if ( field.type ==
'radio' )
1958 var radios = document.getElementsByName(
'$info');
1960 for ( i = 0; i < radios.length; i++ )
1962 radios[i].checked = radios[i].value ==
'$value';
1965else if ( $(field).hasClass(
'm-multiline-field') && $(field).hasClass(
'm-editor') )
1967 eval(
'$ckEditorScript');
1968 editor.setData(
'$value');
1969 field.value =
'$value';
1971else if ( field.className ==
'select m-multitext' )
1973 var v =
'$value'.split(
'@');
1975 for ( i=0; i<v.length; i++)
1982 option = document.createElement(
'option');
1983 option.value = v[i];
1984 option.innerHTML = v[i];
1986 field.appendChild(option);
1991 field.value =
'$value';
1995for (i=0; i < 10; i++)
1997 radio = document.getElementById(
'{$info}_' + i);
1998 if ( radio && radio.value ==
'{$value}' )
2000 radio.checked =
true;
2003if( document.getElementById(
'{$info}_sel') )
2005 document.getElementById(
'{$info}_sel').value=
'{$value}';
2009 SdsetResponse($subClass->generate(
false, $object,
true),
'div' . $object, $temp);
2013 $temp .=
"document.getElementById('arrayItemTemp').value = '';";
2016 SdsetResponse($subClass->generate(
false, $args->MSubDetail,
true),
'div' . $args->MSubDetail, $temp);
2023 $randomid = SAGU::NVL(
$MIOLO->_REQUEST(
"randomid"), $cpaintArgument->randomid);
2025 if ( $_SESSION[
'MSubDetail' . $randomid][
'field_' . $table] )
2027 foreach ( array_keys($_SESSION[
'MSubDetail' . $randomid][
'field_' . $table]) as $field )
2029 if ( $_SESSION[
'MSubDetail' . $randomid][$table] )
2031 foreach ( $_SESSION[
'MSubDetail' . $randomid][$table] as $f )
2033 if ( $f->removeData !=
'TRUE' )
2035 $total[] = $f->$field;
2038 if ( is_array($total) && array_sum($total) )
2040 $t = array_sum($total);
2046 if ( $_SESSION[
'MSubDetail' . $randomid][
'type_' . $table] ==
'TRUE' )
2049 document.getElementById("' . $_SESSION[
'MSubDetail' . $randomid][
'field_' . $table][$field] .
'").value = (' . $t .
').toFixed(2);
2055 document.getElementById("' . $_SESSION[
'MSubDetail' . $randomid][
'field_' . $table][$field] .
'").value = ' . $t .
';
2076 $class = $event->class;
2077 $function = $event->function;
2082 eval(
"{$class}::{$function}(\$values);");
2086 eval(
"{$function}(\$values);");
2098 $randomid = SAGU::NVL(
$MIOLO->_REQUEST(
"randomid"), $cpaintArgument->randomid);
2099 $data = sdAjaxFields($args);
2101 if ( ($event = $_SESSION[
'MSubDetail' . $randomid][
'event'][
'add'] ) )
2103 $class = $event->class;
2104 $function = $event->function;
2107 eval(
"\$data = {$class}::{$function}(\$data);");
2111 eval(
"\$data = {$function}(\$data);");
2119 $data = sdAjaxFields($args);
2121 $class = $event->class;
2122 $function = $event->function;
2125 eval(
"\$data = {$class}::{$function}(\$data);");
2129 eval(
"\$data = {$function}(\$data);");
2141 $class = $event->class;
2142 $function = $event->function;
2145 eval(
"\$data = {$class}::{$function}(\$data);");
2149 eval(
"\$data = {$function}(\$data);");
2163 $class = $event->class;
2164 $function = $event->function;
2168 eval(
"\$values = {$class}::{$function}(\$values);");
2172 eval(
"\$values = {$function}(\$values);");
2189 $class = $event->class;
2190 $function = $event->function;
2194 eval(
"\$values = {$class}::{$function}(\$values);");
2198 eval(
"\$values = {$function}(\$values);");
2215 if ( is_array($fields) )
2217 foreach ( $fields as $line => $field )
2219 echo $field->generate();
2222 else if ( is_object($fields) )
2224 echo $fields->generate();
2234 $js .=
"document.getElementById('divResponse').value = '$divResponse'; ";
2237 echo
"<script type='text/javascript'>$js</script>";
2246 $args = explode(
'#', $args[0]);
2248 foreach ( $args as $line => $info )
2250 $temp = explode(
'|', utf8_encode(urldecode($info)));
2251 if ( ($temp[1] && $temp[1] !=
'undefined') || $temp[1] === 0 || $temp[1] ==
'0' )
2253 $data[$temp[0]] = $temp[1];
2256 $data = (object) $data;
2264 $randomid = SAGU::NVL(
$MIOLO->_REQUEST(
"randomid"), $data->randomid);
2266 $sKey = array_keys($_SESSION[
'MSubDetail' . $randomid][
'field_' . $table]);
2267 foreach ( $data as $key => $value )
2269 if ( $key == $sKey[0] )
2271 $data->$key = number_format(str_replace(
',',
'.', $value), 2,
'.',
'');
2278if ( ($f =
$MIOLO->page->request(
'cpaint_function')) !=
'' )
2280 if ( function_exists($f) )
2282 die($f(
$MIOLO->page->request(
'cpaint_argument')));
setControls($controls, $recursive=false)
addBoxStyle($name, $value='')
const FORM_MODE_SHOW_SIDE
static getCurrentModule()
static _REQUEST( $vars, $from='ALL')
static transformToMValidators($valids)
setShowButtons($showButtons)
static getHideButtonsOnAdd($itemForce=null)
static getValidators($itemForce=null)
setFieldValidators($fields, $validators)
static getDataItem($arrayItem, $itemForce=NULL)
setValidators($validators=null)
setOverFlowWidth($width, $type='auto')
processNamesArray($field)
static getUpdateButton($itemForce=null)
setHideButtonsOnAdd($hide)
static setValidatorsAjax($validators, $item)
__construct($item, $title, $columns=NULL, $fields=NULL, $opts=array('edit', 'remove'), $checkTransaction=NULL)
setDefaultValueFields($fields)
addAction($phpFunction, $img, $imgModule)
static defineData($arrayItem, $obj, $item=NULL)
const HIDDEN_FIELD_PREFIX_NAME
static getSessionValue($var, $itemForce=null)
static setSessionValue($var, $value, $itemForce=null)
getFieldValidator($name, $validators)
static generateActionString($i, $itemForce=NULL)
autoEditAction($args, $values=NULL)
autoForceAddAction($args)
formatFieldToFloat($data, $table)
duplicateFromTable($args)
autoDuplicateAction($args)
SdsetResponse($fields, $divResponse, $js=null)
autoAddAction($data, $object=NULL, $errors=NULL)
getMultipleSelectData($args)