+
+ /**
+ * Write an entry to database. If $mid is 0, a new entry is created.
+ *
+ * @param $mid
+ * @param $props
+ */
+ function writeEntry($mid, $props)
+ {
+ if ($mid == 0) {
+ $props['ordre'] = $this->maxChildIndex($props['parent']) + 1;
+ }
+
+ // build SQL string
+ $nprops = array('parent' => 'MIDpere', 'ordre' => 'ordre', 'title' => 'title', 'link' => 'link', 'pid' => 'pid');
+ $sprops = "";
+ foreach($nprops as $prop => $dbkey)
+ {
+ if (isset($props[$prop]))
+ {
+ $val = $props[$prop];
+ $sprops .= "$dbkey='$val', ";
+ }
+ }
+ if (!$sprops)
+ return;
+ $sprops = substr($sprops, 0, -2);
+ if ($mid == 0) {
+ $this->dbh->query("INSERT INTO {$this->table_menu} SET $sprops");
+ $mid = mysql_insert_id();
+ } else {
+ $this->dbh->query("UPDATE {$this->table_menu} SET $sprops WHERE MID=$mid");
+ }
+ return $mid;
+ }
+