コード例 #1
0
 function submit($project_id = 0, $id = '')
 {
     //prep form data
     $_POST['accountid'] = sess_var('accountid');
     if (!$id) {
         $_POST['projectid'] = $project_id;
     }
     //validate form [perform validation server-side to make sure of fields]
     $this->load->library('form_validation');
     $this->form_validation->set_rules('name', 'Name', 'trim|required');
     if ($this->form_validation->run() == FALSE) {
         //ajax data array
         $data = array('server_validation' => validation_errors());
         echo json_encode($data);
     } else {
         if ($id) {
             $result = $this->units_model->update($id);
             $content = "Unit has been UPDATED successfully";
         } else {
             $result = $this->units_model->add();
             $content = "Unit has been CREATED successfully";
         }
         //if duplicate key
         if ($result == 1062) {
             //ajax data array
             $data = array('is_valid' => 0);
             echo json_encode($data);
         } else {
             //ajax data array
             $data = array('is_valid' => 1, 'content' => $content);
             echo json_encode($data);
         }
     }
     //end ELSE form valid
 }
コード例 #2
0
 function submit($id = '')
 {
     $_POST['accountid'] = sess_var('accountid');
     //validate form
     $this->load->library('form_validation');
     $this->form_validation->set_rules('name', 'Name', 'trim|required');
     if ($this->form_validation->run() == FALSE) {
         //ajax data array
         $data = array('server_validation' => validation_errors());
         echo json_encode($data);
     } else {
         if ($id) {
             $result = $this->countries_model->update($id);
             $content = "Country has been UPDATED successfully";
         } else {
             $result = $this->countries_model->add();
             $content = "Country has been CREATED successfully";
         }
         //if duplicate key
         if ($result == 1062) {
             //ajax data array
             $data = array('is_valid' => 0);
             echo json_encode($data);
         } else {
             //ajax data array
             $data = array('is_valid' => 1, 'content' => $content);
             echo json_encode($data);
         }
     }
     //end ELSE form valid
 }
コード例 #3
0
 function Test()
 {
     parent::Controller();
     if (!sess_var('logged_in')) {
         redirect('login');
     }
 }
コード例 #4
0
 function get_areas_table()
 {
     $this->db->where("accountid ='" . sess_var('accountid') . "'");
     $query = $this->db->get('areas');
     if ($query->num_rows() > 0) {
         $this->load->library('table');
         return $this->table->generate($query);
     }
 }
コード例 #5
0
 function get_media_table($media_type, $entity_type, $entity_id)
 {
     $this->db->where("accountid ='" . sess_var('accountid') . "' AND entitytype ={$entity_type} AND entityid ={$entity_id}");
     $query = $this->db->get($media_type);
     if ($query->num_rows() > 0) {
         $this->load->library('table');
         return $this->table->generate($query);
     }
 }
コード例 #6
0
 function select_fields($id, $fields = 'id')
 {
     $this->db->select($fields);
     $this->db->where("accountid ='" . sess_var('accountid') . "' AND id =" . $id);
     $query = $this->db->get('countries');
     if ($query->num_rows() > 0) {
         return $query->row_array();
     }
 }
コード例 #7
0
 function get_users_table()
 {
     $this->db->select('name , email');
     $this->db->where("accountid ='" . sess_var('accountid') . "'");
     $query = $this->db->get('users');
     if ($query->num_rows() > 0) {
         $this->load->library('table');
         $this->table->set_heading('Name', 'Email');
         return $this->table->generate($query);
     }
 }
コード例 #8
0
 function get_classes($entity_type)
 {
     $this->db->where("accountid ='" . sess_var('accountid') . "' AND entitytype =" . $entity_type);
     $query = $this->db->get('classes');
     if ($query->num_rows() > 0) {
         foreach ($query->result() as $row) {
             $result[] = $row;
         }
         return $result;
     }
 }
コード例 #9
0
 function submit($id = '')
 {
     $_POST['accountid'] = sess_var('accountid');
     //validate form [perform validation server-side to make sure of fields]
     $this->load->library('form_validation');
     $this->form_validation->set_rules('name', 'Name', 'trim|required|min_length[4]');
     $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
     if ($id) {
         $this->form_validation->set_rules('pass', 'Password', 'min_length[6]|max_length[32]|matches[repass]');
     } else {
         $this->form_validation->set_rules('pass', 'Password', 'required|min_length[6]|max_length[32]|matches[repass]');
     }
     $this->form_validation->set_rules('repass', 'Password Confirmation', '');
     if ($this->form_validation->run() == FALSE) {
         //ajax data array
         $data = array('server_validation' => validation_errors());
         echo str_replace('\\/', '/', json_encode($data));
     } else {
         //prep form data
         //remove unwanted elements from the form POST (to be inserted properly)
         unset($_POST['repass']);
         //the following is intended when UPDATE
         if ($_POST['pass']) {
             $_POST['pass'] = md5($_POST['pass']);
         } else {
             unset($_POST['pass']);
         }
         if ($id) {
             $result = $this->users_model->update($id);
             $content = "User has been UPDATED successfully";
         } else {
             $result = $this->users_model->add();
             $content = "User has been CREATED successfully";
         }
         //if duplicate key
         if ($result == 1062) {
             //ajax data array
             $data = array('is_valid' => 0);
             echo json_encode($data);
         } else {
             //ajax data array
             $data = array('is_valid' => 1, 'content' => $content);
             echo json_encode($data);
         }
     }
     //end ELSE form valid
 }
コード例 #10
0
 function upload_media($media_type, $entity_type = '', $entity_id = '', $id = '')
 {
     //prep form data
     $_POST['accountid'] = sess_var('accountid');
     if (!$id) {
         $_POST['entitytype'] = $entity_type;
         $_POST['entityid'] = $entity_id;
     }
     //if not edit (i.e add) or there is upload file then upload else just insert
     if (!$id || $_FILES['userfile']['name']) {
         $config['upload_path'] = 'resources/' . $media_type . '/';
         switch ($media_type) {
             case "files":
                 $allowed_types = "*";
                 $max_size = "16384";
                 break;
             case "images":
                 $allowed_types = "jpg|png|gif";
                 $max_size = "3072";
                 break;
             case "videos":
                 $allowed_types = "flv|mp4|mov";
                 $max_size = "16384";
                 break;
         }
         $config['allowed_types'] = $allowed_types;
         $config['max_size'] = $max_size;
         $this->load->library('upload', $config);
         //if error upload return error
         if (!$this->upload->do_upload()) {
             //ajax data array
             $data = array('is_valid' => 0, 'error' => $this->upload->display_errors());
             //echo str_replace('\\/', '/', json_encode($data));
             echo json_encode($data);
             return;
         } else {
             $file_data = $this->upload->data();
             $_POST['path'] = base_url() . $config['upload_path'];
             $_POST['name'] = $file_data['file_name'];
             $_POST['size'] = $file_data['file_size'];
             //reize images
             $this->load->helper("resize_image");
             if ($media_type == "images") {
                 resizeimage($file_data['full_path'], 136, 102, 80, "crop", $config['upload_path'] . "thumbs/" . $_POST['name']);
                 //so that not to enlarge the image in medium version
                 if ($file_data['image_width'] > 800 || $file_data['image_height'] > 600) {
                     resizeimage($file_data['full_path'], 800, 600, 80, "scale", $config['upload_path'] . "med/" . $_POST['name']);
                 } else {
                     copy($file_data['full_path'], $config['upload_path'] . "med/" . $_POST['name']);
                 }
             } else {
                 if ($media_type == "videos" && $_FILES['userfile2']['name']) {
                     $config2['upload_path'] = 'resources/videos/thumbs/';
                     $config2['allowed_types'] = 'jpg|png|gif';
                     $config2['max_size'] = '1024';
                     $this->upload->initialize($config2);
                     //if error upload return error
                     if (!$this->upload->do_upload('userfile2')) {
                         //ajax data array
                         $data = array('is_valid' => 0, 'error2' => $this->upload->display_errors());
                         echo json_encode($data);
                         //delete the video file if it was uploaded
                         if (is_file($config['upload_path'] . '/' . $_POST['name'])) {
                             unlink($config['upload_path'] . '/' . $_POST['name']);
                         }
                         return;
                     } else {
                         $file_data = $this->upload->data();
                         $_POST['thumb'] = $file_data['file_name'];
                         //resize thumbnail image
                         resizeimage($file_data['full_path'], 90, 65, 80, "crop", $file_data['full_path']);
                     }
                 }
             }
             //if edit (get old file name then delete after the insert)
             if ($id) {
                 $result = $this->media_model->get_name($media_type, $id);
                 $file_name = $result['name'];
                 $thumb = $result['thumb'];
             }
         }
     }
     //end if
     /*********** insert record into database ***********/
     //if edit
     if ($id) {
         $error = $this->media_model->update($media_type, $id);
         $content = $media_type . " has been UPDATED successfully";
     } else {
         $error = $this->media_model->add($media_type);
         $content = $media_type . " has been ADDED successfully";
     }
     if (!$error) {
         //if edit then delete old file
         if ($id && $_FILES['userfile']['name']) {
             if (is_file($config['upload_path'] . $file_name)) {
                 unlink($config['upload_path'] . $file_name);
             }
             if ($media_type == "images") {
                 if (is_file($config['upload_path'] . "thumbs/" . $file_name)) {
                     unlink($config['upload_path'] . "thumbs/" . $file_name);
                 }
                 if (is_file($config['upload_path'] . "med/" . $file_name)) {
                     unlink($config['upload_path'] . "med/" . $file_name);
                 }
             }
             if ($media_type == "videos" && $_FILES['userfile2']['name']) {
                 if (is_file($config['upload_path'] . "thumbs/" . $thumb)) {
                     unlink($config['upload_path'] . "thumbs/" . $thumb);
                 }
             }
         }
         //ajax data array
         $data = array('is_valid' => 1, 'content' => $content);
         echo json_encode($data);
     }
 }
コード例 #11
0
		  <span></span>
      </li>
      <li class="mi">
          <a href="#">Classes</a>
          <ul class="subnav">
              <li><a href="javascript:load_content('countries')">Manage Countries</a></li>
              <li><a href="#">Manage Cities</a></li>
              <li><a href="#">Manage Areas</a></li>
              <li><a href="javascript:load_content('classes/6')">Unit Types</a></li>
          </ul>
		  <span></span>
      </li>
      <li class="mi">
          <a href="#">Admin</a>
          <ul class="subnav">
              <li><a href="#">Admin Profile</a></li>
              <li><a href="javascript:load_content('users')">Manage Users</a></li>
              <li><a href="javascript:load_content('users/add')">Create User</a></li>
          </ul>
		  <span></span>
      </li>
      <li><a href="#">Help</a></li>
</ul>
<div class="login_welcome">
  welcome <strong><?php 
echo sess_var('name');
?>
</strong> <a href="login/logout">logout</a>
</div>
<div style="clear:both"></div>
</div>