public static function remove($report_id)
 {
     $q = new dquery(RUDE_DATABASE_TABLE_CALENDAR_ITEMS);
     $q->where(RUDE_DATABASE_FIELD_REPORT_ID, (int) $report_id);
     $q->query();
     return $q->affected();
 }
 public static function remove($item_id)
 {
     if (static::is_exists($item_id)) {
         $q = new dquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES);
         $q->where('item_id', (int) $item_id);
         $q->query();
         return $q->affected();
     }
     return false;
 }
 public static function remove($id)
 {
     if (static::is_exists($id)) {
         $q = new dquery(RUDE_DATABASE_TABLE_REPORTS_CATEGORIES_ITEMS);
         $q->where(RUDE_DATABASE_FIELD_ID, (int) $id);
         $q->query();
         return $q->affected();
     }
     return false;
 }
 public static function remove($id)
 {
     if (static::is_exists($id)) {
         $q = new dquery(RUDE_DATABASE_TABLE_CALENDAR_LEGEND);
         $q->where(RUDE_DATABASE_FIELD_ID, (int) $id);
         $q->query();
         return $q->affected();
     }
     return false;
 }
 public static function remove($id)
 {
     if (static::is_exists($id)) {
         $q = new dquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_PREVIEW);
         $q->where(RUDE_DATABASE_FIELD_ID, (int) $id);
         $q->query();
         return $q->affected();
     }
     return false;
 }
 public function __construct()
 {
     if (!template_session::is_admin() and !template_session::is_editor()) {
         if (get('ajax')) {
             exit(RUDE_AJAX_ACCESS_VIOLATION);
         }
         return false;
     }
     $report_id = (int) get('report_id');
     if (!$report_id) {
         $reports = new reports();
         $report_id = $reports::add();
         header('Location: /?page=reports-edit&report_id=' . $report_id);
         die;
     }
     if (get('is_tmp')) {
         $reports = new reports_preview();
     } else {
         $reports = new reports();
     }
     if (!$reports::is_exists($report_id)) {
         new template_404(true);
     }
     $this->report = $reports::get($report_id);
     if (!$this->report) {
         new template_404(true);
     }
     switch (get('task')) {
         case 'update':
             $status = true;
             exit((string) $reports::update(get('report_id'), get('year'), get('duration'), get('rector'), get('registration_number'), get('training_form_id'), get('qualification_id'), get('specialty_id'), get('specialization_id'), get('study_practice'), get('manufact_practice'), get('grad_work'), get('gos_exam')));
             break;
         case 'update_education':
             $q = new uquery(RUDE_DATABASE_TABLE_EDUCATION);
             $q->update('not_save', (int) 0);
             $q->where('id', (int) get('dis_id'));
             $q->query();
             $status = true;
             break;
         case 'update_education_item':
             $q = new uquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS);
             $q->update('order_num', (int) get('item_order'));
             $q->update('is_optional', (int) get('optional'));
             $q->where('id', (int) get('item_id'));
             $q->query();
             $status = true;
             break;
         case 'delete_item_discipline':
             $q = new dquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS);
             $q->where('id', (int) get('id'));
             $q->query();
             $status = true;
             break;
         case 'save_education':
             $data = get('data');
             $item_id = get('item_id');
             if (!$data or !$item_id) {
                 return false;
             }
             $education_items = new education_items_values();
             if ($education_items::is_exists($item_id)) {
                 $education_items::remove($item_id);
             }
             $y = 0;
             $id = $item_id[$y];
             foreach ($item_id as $d_id) {
                 $q = new dquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES);
                 $q->where('item_id', $d_id);
                 $q->query();
             }
             $col_num = 1;
             foreach ($data as $item) {
                 if ($item != '') {
                     $education_items::add($id, $item, $col_num);
                 }
                 if ($col_num == 40) {
                     $col_num = 0;
                     $id = $item_id[$y + 1];
                     $y++;
                 }
                 $col_num++;
             }
             //debug($data);
             $status = true;
             break;
         case 'add_education':
             $tmp = education::add(get('report_id'), get('name'));
             $status = true;
             die(json_encode($tmp));
             break;
         case 'remove_education':
             education::remove(get('id'));
             break;
         case 'add_education_item':
             $tmp = education_items::add(get('education_id'), get('name'), get('order'));
             $status = true;
             die(json_encode($tmp));
             break;
         case 'copy_education':
             $education = education::get(get('dis_id'));
             $q = new cquery(RUDE_DATABASE_TABLE_EDUCATION_PREVIEW);
             $q->add('report_id', (int) get('report_id'));
             $q->add('name', $education->name);
             $q->query();
             $new_id = $q->get_id();
             $q = new query(RUDE_DATABASE_TABLE_EDUCATION_ITEMS);
             $q->where('education_id', (int) get('dis_id'));
             $q->query();
             $all_dis = $q->get_object_list();
             foreach ($all_dis as $cur_dis) {
                 $q = new cquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_PREVIEW);
                 $q->add('name', $cur_dis->name);
                 $q->add('education_id', $new_id);
                 $q->add('order_num', $cur_dis->order_num);
                 $q->add('is_optional', $cur_dis->is_optional);
                 $q->query();
                 $new_item_id = $q->get_id();
                 $q = new query(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES);
                 $q->where('item_id', $cur_dis->id);
                 $q->query();
                 $all_item_val = $q->get_object_list();
                 foreach ($all_item_val as $cur_item_val) {
                     $q = new cquery(RUDE_DATABASE_TABLE_EDUCATION_ITEMS_VALUES_PREVIEW);
                     $q->add('value', $cur_item_val->value);
                     $q->add('item_id', $new_item_id);
                     $q->add('col_num', $cur_item_val->col_num);
                     $q->query();
                 }
             }
             $status = true;
             break;
         default:
             $status = false;
             break;
     }
     if (get('ajax')) {
         if ($status) {
             exit(RUDE_AJAX_OK);
         } else {
             exit(RUDE_AJAX_ERROR);
         }
     }
     return true;
 }