예제 #1
0
 function draw_widgets($template_id, $position, $preview = FALSE)
 {
     $CI = get_instance();
     $CI->db->where('id', $template_id);
     $query = $CI->db->get('templates', 1);
     if ($query->num_rows() > 0) {
         $row = $query->row();
         $widgets = unserialize($row->widgets);
         if (!isset($widgets[$position])) {
             return FALSE;
         }
         $widgets[$position] = explode(',', $widgets[$position]);
         foreach ($widgets[$position] as $widget) {
             draw_widget($widget, $position, $preview);
         }
     } else {
         return FALSE;
     }
 }
예제 #2
0
 function _save_widget()
 {
     $response = array('success' => FALSE, 'error' => '');
     if ($this->input->post()) {
         $this->form_validation->set_rules('widget_type', 'Widget Type', "trim|required");
         $this->form_validation->set_rules('user_id', 'User ID', 'trim|required');
         $this->form_validation->set_rules('template_id', 'Template ID', 'trim|required');
         if ($this->form_validation->run() == TRUE) {
             if (!$this->input->post('widget_id') || !valid_widget_id($this->input->post('widget_id'))) {
                 //save widget
                 $insert['template_id'] = (int) $this->input->post('template_id');
                 $insert['widget_type'] = $this->input->post('widget_type');
                 $this->db->insert('widgets', $insert);
                 $widget_id = $this->db->insert_id();
                 ob_start();
                 draw_modal($widget_id);
                 $response = array('success' => TRUE, 'widget_modal' => ob_get_contents(), 'widget_id' => 'widget-' . $insert['widget_type'] . '-' . $widget_id);
                 ob_end_clean();
             } elseif (valid_widget_id($this->input->post('widget_id'))) {
                 //update widget
                 $widget_id = preg_replace("/[^0-9]/", "", $this->input->post('widget_id'));
                 $update['widget_data'] = $this->_get_widget_data();
                 if ($update['widget_data']) {
                     $this->db->where('id', $widget_id);
                     $this->db->where('template_id', $this->input->post('template_id'));
                     $this->db->update('widgets', $update);
                     if ($this->db->affected_rows() > 0) {
                         ob_start();
                         draw_widget($widget_id);
                         $response = array('success' => TRUE, 'widget_html' => ob_get_contents(), 'widget_id' => 'widget-' . $this->input->post('widget_type') . '-' . $widget_id);
                         ob_end_clean();
                     } else {
                         $response['error'] = 'Nothing change';
                     }
                 } else {
                     $response['error'] = 'Invalid widget data.';
                 }
             }
         }
     }
     echo json_encode($response);
     exit;
 }