<?php

/* CLASS FILE
----------------------------------*/

class box extends db {

  public $dt;
  public $settings;

  public function add($fm) {
    db::db_query("INSERT INTO `" . DB_PREFIX . "boxes` (
    `title`,
	  `info`,
	  `en`,
	  `tmp`,
    `icon`
    ) VALUES (
    '" . db::db_escape($fm['title']) . "',
    '" . db::db_escape($fm['info']) . "',
    '{$fm['en']}',
    '" . db::db_escape($fm['tmp']) . "',
    '" . db::db_escape($fm['icon']) . "'
    )");
    $ID = db::db_last_insert_id();
    db::db_query("UPDATE `" . DB_PREFIX . "boxes` SET `ordr` = '{$ID}' WHERE `id` = '{$ID}'");
    return $ID;
  }

  public function update($fm) {
    db::db_query("UPDATE `" . DB_PREFIX . "boxes` SET
    `title` = '" . db::db_escape($fm['title']) . "',
	  `info`  = '" . db::db_escape($fm['info']) . "',
	  `en`    = '{$fm['en']}',
	  `tmp`   = '" . db::db_escape($fm['tmp']) . "',
    `icon`   = '" . db::db_escape($fm['icon']) . "'
    WHERE `id` = '{$fm['id']}'
    ");
  }

  public function delete($fm) {
    db::db_query("DELETE FROM `" . DB_PREFIX . "boxes` WHERE `id` IN(" . db::db_escape(implode(',', $fm['ids'])) . ")");
    db::db_truncate(array('boxes'));
  }

  public function order($fm) {
    $cnt = 0;
    foreach ($fm['sort'] AS $id) {
      db::db_query("UPDATE `" . DB_PREFIX . "boxes` SET
      `ordr`  = '" . (++$cnt) . "'
      WHERE `id` = '{$id}'
      ");
    }
  }

}

?>