Exemple #1
0
 function formize($column, $repopulate)
 {
     $CI =& get_instance();
     if ($repopulate && $CI->input->post()) {
         $column['value'] = set_value($column['name']) == "" ? $column["value"] : set_value($column['name']);
     }
     if (isset($column['preferences'])) {
         $column['value'] = get_setting($column['name']);
     }
     if (isset($column['serialized']) && $column['serialized']) {
         $column['value'] = unserialize($column["value"]);
     }
     //if($column['type'] == 'input' || $column['type'] == 'nation') $column['value'] = set_value($column['name']);
     if ($column['type'] == 'checkbox') {
         if (!is_array($column['value'])) {
             if ($column['value'] == 1) {
                 $column['checked'] = 'checked';
             }
             $column['value'] = 1;
         }
     }
     $formize = 'form_' . $column['type'];
     if (!isset($column['type'])) {
         $formize = "";
     }
     $type = $column['type'];
     if (isset($column['help'])) {
         $help = $column['help'];
     }
     if (isset($column['text'])) {
         $text = $column['text'];
     }
     if (isset($column['field'])) {
         $column['id'] = $column['field'];
     } else {
         $column['id'] = $column['name'];
     }
     if ($type == 'checkbox' && isset($column['values'])) {
         unset($column['values']);
     }
     unset($column['rules']);
     unset($column['field']);
     unset($column['type']);
     unset($column['preferences']);
     unset($column['text']);
     unset($column['help']);
     if (is_array($column['value'])) {
         if ($type == 'checkbox') {
             $result = array();
             $minion = $column['value'];
             $result[] = '<ul class="inputs-list">';
             foreach ($minion as $mini) {
                 $mini['type'] = 'checkbox';
                 $result[] = '<li><label>' . formize($mini, FALSE) . '</label></li>';
             }
             $result[] = '</ul>';
         } else {
             $column['name'] .= '[]';
             $minion = $column['value'];
             foreach ($minion as $mini) {
                 if (isset($mini->name)) {
                     $column['value'] = $mini->name;
                 } else {
                     $column['value'] = $mini;
                 }
                 $result[] = $formize($column);
             }
             if (empty($result)) {
                 $column['value'] = "";
                 $result[] = $formize($column);
             }
             $column['value'] = "";
             $column['onKeyUp'] = "addField(this);";
             $result[] = $formize($column);
         }
     } else {
         // echo '<pre>'; print_r($column); echo '</pre>';
         if ($type == 'hidden' && isset($column["value"])) {
             $result = $formize($column['name'], $column['value']);
         } else {
             $result = $formize($column);
         }
     }
     if (is_array($result)) {
         $results = $result;
         $result = "";
         foreach ($results as $resulting) {
             $result .= $resulting;
             if ($type != 'checkbox') {
                 $result .= '<br/>';
             }
         }
     }
     if (isset($text) && !is_array($column['value'])) {
         $result = $result . ' <span>' . $text . '</span>';
     }
     if (isset($help)) {
         $result = $result . '<span class="help-block">' . $help . '</span>';
     }
     return $result;
 }
Exemple #2
0
	function tabler($rows, $list = TRUE, $edit = TRUE, $repopulate = FALSE) {
		$result = array();
		$CI = & get_instance();


		$rows[] = array(
			"",
			array(
				'type' => 'submit',
				'name' => 'submit',
				'id' => 'submit',
				'value' => _('Save')
			)
		);

		$echo = "";

		foreach ($rows as $rowk => $row) {
			foreach ($row as $colk => $column) {
				if ($colk == 0) {
					$result[$rowk][$colk]["table"] = $column;
					$result[$rowk][$colk]["form"] = $column;
				}
				else {
					if (!isset($column['value']))
						$column['value'] = "";
					if (is_array($column)) {
						$result[$rowk][$colk]["table"] = writize($column);
						if (isset($column['type'])) {
							$result[$rowk][$colk]["form"] = formize($column, $repopulate);
							$result[$rowk][$colk]["type"] = $column['type'];
						}
					}
					else {
						$result[$rowk][$colk]["table"] = writize($column);
						$result[$rowk][$colk]["form"] = $column;
					}
				}
			}
		}

		// echo '<pre>'; print_r($result); echo '</pre>';
		if ($list && $edit) {
			$CI->buttoner[] = array(
				'text' => _('Edit'),
				'href' => '',
				'onclick' => "slideToggle('.plain'); slideToggle('.edit'); return false;"
			);
		}

		if ($list) {
			$echo .= '<div class="plain"><table class="form">';
			foreach ($result as $rowk => $row) {
				if (isset($row[1]['type']) && $row[1]['type'] == 'hidden') {
					//$echo .= $row[1]['form'];
				}
				else {
					if (!isset($row[1]) || $row[1]['table'] != _('Save') && $row[0]['table'] != 'id') {
						$echo .= '<tr>';
						foreach ($row as $column) {
							$echo .= '<td>';
							if (is_array($column['table'])) {
								foreach ($column['table'] as $mini) {
									$echo .= '' . $mini->name . ' ';
								}
							}
							else if ($column['table'] == "")
								$echo .= 'N/A';
							else
								$echo .= $column['table'];
							$echo .= '</td>';
						}
						$echo .= '</tr>';
					}
				}
			}
			$echo .= '</table></div>';
		}


		if ($edit) {
			$echo .= '<div class="edit" ' . (($list && $edit) ? 'style="display:none;"' : '') . '><table class="form">';
			foreach ($result as $rowk => $row) {
				if ($row[1]['type'] == 'hidden') {
					$echo .= $row[1]['form'];
				}
				else {
					$echo .= '<tr>';
					foreach ($row as $column) {
						$echo .= '<td>';
						$echo .= $column['form'];
						$echo .= '</td>';
					}
					$echo .= '</tr>';
				}
			}
			$echo .= '</table></div>';
		}
		return $echo;
	}