X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fpltableeditor.php;h=430cc1512781430bf1ea10a081bcad28a704b477;hb=6c85148b00f7b0b8d4c39393069ddc97b657044a;hp=39eb9e751cd2b8c44f57951adcd00c4f87b99dd7;hpb=386b75eab9e8f1611b2e5f1e7aa3a4ab3da4dbf4;p=platal.git diff --git a/classes/pltableeditor.php b/classes/pltableeditor.php index 39eb9e7..430cc15 100644 --- a/classes/pltableeditor.php +++ b/classes/pltableeditor.php @@ -1,6 +1,6 @@ pl = $plname; $this->table = $table; $this->idfield = $idfield; @@ -61,7 +62,7 @@ class PLTableEditor { // desc will be the title of the column $a['desc'] = $a['Field']; $a['display'] = true; - + if (substr($a['Type'],0,8) == 'varchar(') { // limit editing box size $a['Size'] = $a['Maxlength'] = substr($a['Type'], 8, strlen($a['Type']) - 9); @@ -74,7 +75,12 @@ class PLTableEditor { elseif (substr($a['Type'],0,4) == 'set(') { // get the list of options $a['List'] = explode('§',str_replace("','","§",substr($a['Type'], 5, strlen($a['Type']) - 7))); - $a['Type'] = 'set'; + if (count($a['List']) == 1) { + $a['Type'] = 'checkbox'; + $a['Value'] = $a['List'][0]; + } else { + $a['Type'] = 'set'; + } } elseif (substr($a['Type'],0,5) == 'enum(') { // get the list of options @@ -89,6 +95,15 @@ class PLTableEditor { } $this->vars[$idfield]['desc'] = 'id'; } + // called before creating a new entry + function prepare_new() + { + $entry = array(); + foreach ($this->vars as $field => $descr) { + $entry[$field] = $descr['Default']; + } + return $this->prepare_edit($entry); + } // called before editing $entry function prepare_edit(&$entry) { foreach ($this->vars as $field => $descr) { @@ -102,7 +117,7 @@ class PLTableEditor { if ($descr['Type'] == 'timestamp') { // set readable timestamp $date =& $entry[$field]; - $date = preg_replace('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', '\3/\2/\1 \4:\5:\6', $date); + $date = preg_replace('/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/', '\3/\2/\1 \4:\5:\6', $date); } if ($descr['Type'] == 'date') { $date =& $entry[$field]; @@ -116,7 +131,7 @@ class PLTableEditor { $this->vars[$name]['desc'] = $desc; $this->vars[$name]['display'] = $display; } - // add a join table, when deleting a row corresponding entries will be deleted in these tables + // add a join table, when deleting a row corresponding entries will be deleted in these tables function add_join_table($name,$joinid,$joindel,$joinextra="") { if ($joindel) $this->jtables[$name] = array("joinid" => $joinid,"joinextra" => $joinextra?(" AND ".$joinextra):""); @@ -138,7 +153,7 @@ class PLTableEditor { } // call when done function apply(&$page, $action, $id = false) { - $page->changeTpl('table-editor.tpl'); + $page->changeTpl('core/table-editor.tpl'); $list = true; if ($action == 'delete') { if (!isset($this->delete_action)) { @@ -164,10 +179,24 @@ class PLTableEditor { $page->assign('id', $id); $list = false; } + if ($action == 'massadd') { + $importer = new CSVImporter($this->table, $this->idfield_editable ? $this->idfield : null); + $fields = array(); + foreach ($this->vars as $field=>$descr) { + if ($this->idfield_editable || $field != $this->idfield) { + $fields[] = $field; + $importer->describe($field, @$descr['desc']); + } + } + $page->assign('massadd', true); + $importer->apply($page, $this->pl . '/massadd', $fields); + $list = false; + } if ($action == 'new') { if (!$this->idfield_editable) { $r = XDB::query("SELECT MAX({$this->idfield})+1 FROM {$this->table}"); $page->assign('id', $r->fetchOneCell()); + $page->assign('entry', $this->prepare_new()); } $list = false; } @@ -185,10 +214,12 @@ class PLTableEditor { $val .= $option; } $val = "'".addslashes($val)."'"; + } elseif ($descr['Type'] == 'checkbox') { + $val = Post::has($field)?"'".addslashes($descr['Value'])."'":"''"; } elseif (Post::has($field)) { - $val = Post::v($field); + $val = Post::v($field); if ($descr['Type'] == 'timestamp') { - $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/', '\3\2\1\4\5\6', $val); + $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/', '\3\2\1\4\5\6', $val); } elseif ($descr['Type'] == 'date') { $val = preg_replace('/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})/', '\3-\2-\1', $val); @@ -196,7 +227,7 @@ class PLTableEditor { $val = "'".addslashes($val)."'"; } else { $cancel = true; - $page->trig("Il manque le champ ".$field); + $page->trig("Il manque le champ ".$field); } $values .= $val; }