Exemplo n.º 1
11
 function html_purify($dirty_html, $config = FALSE)
 {
     require_once APPPATH . 'third_party/htmlpurifier-4.6.0-standalone/HTMLPurifier.standalone.php';
     if (is_array($dirty_html)) {
         foreach ($dirty_html as $key => $val) {
             $clean_html[$key] = html_purify($val, $config);
         }
     } else {
         $ci =& get_instance();
         switch ($config) {
             //settings for rhe WYSIWYG
             case 'comment':
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', $ci->config->item('charset'));
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 $config->set('HTML.Allowed', 'a[href|title],img[title|src|alt],em,strong,cite,blockquote,code,ul,ol,li,dl,dt,dd,p,br,h1,h2,h3,h4,h5,h6,span,*[style]');
                 $config->set('AutoFormat.AutoParagraph', TRUE);
                 $config->set('AutoFormat.Linkify', TRUE);
                 $config->set('AutoFormat.RemoveEmpty', TRUE);
                 break;
             case FALSE:
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', $ci->config->item('charset'));
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 break;
             default:
                 show_error('The HTMLPurifier configuration labeled "' . htmlentities($config, ENT_QUOTES, 'UTF-8') . '" could not be found.');
         }
         $purifier = new HTMLPurifier($config);
         $clean_html = $purifier->purify($dirty_html);
     }
     return $clean_html;
 }
 function html_purify($dirty_html, $config = FALSE)
 {
     require_once APPPATH . 'third_party/htmlpurifier-4.6.0-standalone/HTMLPurifier.standalone.php';
     if (is_array($dirty_html)) {
         foreach ($dirty_html as $key => $val) {
             $clean_html[$key] = html_purify($val, $config);
         }
     } else {
         $ci =& get_instance();
         switch ($config) {
             case 'comment':
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', $ci->config->item('charset'));
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 $config->set('HTML.Allowed', 'p,a[href|title],abbr[title],acronym[title],b,strong,blockquote[cite],code,em,i,strike');
                 $config->set('AutoFormat.AutoParagraph', TRUE);
                 $config->set('AutoFormat.Linkify', TRUE);
                 $config->set('AutoFormat.RemoveEmpty', TRUE);
                 break;
             case FALSE:
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', $ci->config->item('charset'));
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 break;
             default:
                 show_error('The HTMLPurifier configuration labeled "' . htmlentities($config, ENT_QUOTES, 'UTF-8') . '" could not be found.');
         }
         $purifier = new HTMLPurifier($config);
         $clean_html = $purifier->purify($dirty_html);
     }
     return $clean_html;
 }
Exemplo n.º 3
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('c_name', 'Club\'s name', 'required');
     $this->form_validation->set_rules('c_full_name', 'Club\'s full name', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("club_id") != NULL) {
             $query = $this->db->get_where('clubs', array('id' => $this->input->get('club_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Club exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Club_form', $form_data);
         } else {
             $this->load->view('Club_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('c_name' => html_purify($this->input->post('c_name')), 'c_full_name' => html_purify($this->input->post('c_full_name')), 'about_us' => html_purify($this->input->post('about_us')), 'faculty' => html_purify($this->input->post('faculty')), 'students' => html_purify($this->input->post('students')), 'tagline' => html_purify($this->input->post('tagline')));
         if ($this->input->get('club_id') != "") {
             // update
             $this->db->update('clubs', $form_data, " id = '" . $this->input->get('club_id') . "'");
             $this->logger->insert('Updated club ' . html_purify($this->input->post('c_name')) . ' (' . $this->input->get('club_id') . ')');
         } else {
             $this->db->insert('clubs', $form_data);
             $this->logger->insert('Created club ' . html_purify($this->input->post('c_name')));
         }
         redirect(base_url() . 'Clubs/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 4
0
 /**
  * Processes comment data and inserts it
  * into the database
  * 
  * @param string $module      Name of the module
  * @param string $module_link Link from where comment was called
  */
 public function add($module, $module_link)
 {
     $this->load->library('form_validation');
     $this->load->model('comments_m');
     $this->load->helper('htmlpurifier');
     $this->form_validation->set_rules('content', 'Comment content', 'trim|required|min_length[5]');
     if ($this->ion_auth->logged_in() && $this->form_validation->run()) {
         // Found fields that need to be empty. Are you a spam bot?
         $fakeField1 = $this->input->post('usernamef');
         $fakeField2 = $this->input->post('emailf');
         if (!empty($fakeField1) || !empty($fakeField2)) {
             redirect($this->agent->referrer());
         }
         $lastComment = $this->comments_m->getLastUserComment($this->user->id);
         $timeComment = strtotime($lastComment[0]->date);
         $timeDiff = time() - $timeComment;
         // Flood protection
         if ($timeDiff <= $this->setting->commentsdelay) {
             $this->session->set_flashdata('comment_error', 'You\'re typing too fast!');
             redirect($this->agent->referrer());
         }
         $data = array('content' => html_purify($this->input->post('content'), 'comment'), 'poster_id' => $this->user->id, 'module' => $module, 'module_link' => $module_link, 'date' => date('Y-m-d H:i:s'));
         $this->comments_m->insert($data);
         redirect($this->agent->referrer());
     } else {
         $this->session->set_flashdata('comment_error', validation_errors('', ''));
         redirect($this->agent->referrer() . '#errors');
     }
 }
Exemplo n.º 5
0
 function index()
 {
     if ($this->session->userdata('loggedin') == 1) {
         //No registration for registered users
         redirect('/login');
     }
     $this->load->helper(array('form', 'url'));
     $this->load->library('form_validation');
     $this->form_validation->set_rules('username', 'Username', 'required');
     $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
     $this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]|min_length[6]');
     $this->form_validation->set_rules('passconf', 'Password confirmation', 'required');
     $this->form_validation->set_rules('full_name', 'Full Name', 'required');
     $this->form_validation->set_rules('username', 'Username', 'required|callback_check_details');
     $this->form_validation->set_rules('email', 'email', 'required|callback_check_email');
     $this->form_validation->set_rules('roll_number', 'roll_number', 'callback_check_roll_no');
     if ($this->form_validation->run() == FALSE) {
         $this->load->view('registration_form');
     } else {
         $this->load->helper('htmlpurifier');
         $password = $this->input->post('password');
         $hash = $this->bcrypt->hash_password($password);
         $confirmation_link = bin2hex(openssl_random_pseudo_bytes(18));
         // 36 character lin
         $form_data = array('username' => html_purify($this->input->post('username')), 'email' => html_purify($this->input->post('email')), 'type' => 'student', 'full_name' => html_purify($this->input->post('full_name')), 'roll_number' => html_purify($this->input->post('roll_number')), 'password' => $hash, 'confirmation_link' => $confirmation_link);
         $this->db->insert('users', $form_data);
         $user_id = $this->db->insert_id();
         $this->logger->insert("Registered", TRUE, TRUE, $user_id);
         $this->send_mail($form_data['username'], $form_data['confirmation_link'], $form_data['full_name'], $form_data['email']);
         $data['message'] = 'Your account has been successfully created. <br />' . ' A confirmation link has been sent to your email address to activate your account';
         $this->load->view('Success_message', $data);
     }
 }
Exemplo n.º 6
0
 public function edit($id = 0)
 {
     $this->load->helper('form');
     $this->load->helper('htmlpurifier');
     $this->load->library('form_validation');
     $this->template->append_metadata(Assets::adminJs('ckeditor', 'js/ckeditor'));
     $this->form_validation->set_rules('name', 'Name', 'required|trim|htmlspecialchars|min_length[4]|xss_clean');
     $this->form_validation->set_rules('slug', 'Page slug', 'required|max_length[30]|min_length[3]|is_unique[pages.slug]');
     $this->form_validation->set_rules('access', 'Access level', 'required');
     $this->form_validation->set_rules('navigation', 'Navigation link name', 'trim|required|min_length[4]|htmlspecialchars|max_length[20]|xss_clean');
     $this->form_validation->set_rules('content', 'Content', 'required');
     if ($this->form_validation->run() == TRUE) {
         $navLink = $this->input->post('navigation');
         $oldSlug = $this->pages_m->get($id)->slug;
         $slug = makePageSlug($this->input->post('slug'));
         $data = array('name' => $this->input->post('name'), 'description' => html_purify($this->input->post('description'), 'description'), 'slug' => $slug, 'content' => html_purify($this->input->post('content'), 'wysiwyg'), 'navigation' => $navLink, 'layout' => $this->input->post('layout'), 'date' => date('Y-m-d H:i'), 'access' => $this->input->post('access'));
         $this->pages_m->update($id, $data);
         // Edit navigation link
         $this->load->model('navigation/navigation_m');
         $this->navigation_m->delete_by(array('link' => $oldSlug));
         $dataNav = array('name' => $navLink, 'link' => $slug, 'type' => 'uri');
         $this->navigation_m->insert($dataNav);
         redirect('admin/pages');
     } else {
         $this->template->set('title', 'Edit page')->set('data', $this->pages_m->as_array()->get($id))->set('layouts', $this->template->get_theme_layouts($this->setting->theme))->build('admin/form');
     }
 }
Exemplo n.º 7
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('roll_no', 'Roll Number', 'required');
     $this->form_validation->set_rules('program_id', 'Program', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("student_id") != NULL) {
             $query = $this->db->get_where('student_details', array('id' => $this->input->get('student_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Student exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Student_form', $form_data);
         } else {
             $this->load->view('Student_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         if ($this->input->get('student_id') != "") {
             // update
             $form_data = array('roll_no' => html_purify($this->input->post('roll_no')), 'program_id' => html_purify($this->input->post('program_id')));
             $this->db->update('student_details', $form_data, " id = '" . $this->input->get('student_id') . "'");
             $this->logger->insert('Updated Roll Number' . $this->input->post('roll_no') . ' (' . $this->input->get('student_id') . ')');
         } else {
             $arr = explode(' ', html_purify($this->input->post('roll_no')));
             if (!isset($arr[2])) {
                 $form_data = array('roll_no' => html_purify($this->input->post('roll_no')), 'program_id' => html_purify($this->input->post('program_id')));
                 $this->db->insert('student_details', $form_data);
                 $this->logger->insert('Created roll number - ' . $this->input->post('roll_no'));
             } else {
                 $roll_prefix = $arr[0];
                 $roll_beg = $arr[1];
                 $roll_end = $arr[2];
                 $form_data = array('program_id' => html_purify($this->input->post('program_id')));
                 $beg_len = strlen($roll_beg);
                 $end_len = strlen($roll_end);
                 if ($end_len > $beg_len) {
                     $max_len = $end_len;
                 } else {
                     $max_len = $beg_len;
                 }
                 for ($i = $roll_beg; $i <= $roll_end; $i++) {
                     $new_roll_no = $roll_prefix . str_pad($i, $max_len, "0", STR_PAD_LEFT);
                     $form_data['roll_no'] = $new_roll_no;
                     $this->db->insert('student_details', $form_data);
                 }
                 $this->logger->insert('Created roll numbers Range - ' . $this->input->post('roll_no'));
             }
         }
         redirect(base_url() . 'Students/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 8
0
 function html_purify($dirty_html, $config = FALSE)
 {
     require_once APPPATH . 'third_party/htmlpurifier-4.5.0-standalone/HTMLPurifier.standalone.php';
     if (is_array($dirty_html)) {
         foreach ($dirty_html as $key => $val) {
             $clean_html[$key] = html_purify($val, $config);
         }
     } else {
         switch ($config) {
             case 'comment':
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', 'utf-8');
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 $config->set('HTML.Allowed', 'a[href|title],b,strong,blockquote[cite],em,i,strike');
                 $config->set('AutoFormat.Linkify', TRUE);
                 $config->set('AutoFormat.RemoveEmpty', TRUE);
                 break;
             case 'description':
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 $config->set('HTML.Allowed', 'a[href|title],b,strong,img');
                 break;
             case 'wysiwyg':
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', 'utf-8');
                 $config->set('HTML.Allowed', 'p[style],a[href|title],abbr[title],acronym[title],b,strong,blockquote[cite],code,em,i,strike,u,s,sub,sup,ol,ul,li,hr,img[src|alt|title|style],table[border|cellspacing|cellpadding|width|align|summary|bgcolor|style],tr,tbody,td[colspan|rowspan|width|height|align|valign|bgcolor],th[colspan|rowspan|width|height|align|valign],div,h1,h2,h3,h4,h5,h6,object[width|height|data],param[name|value],embed[src|type|allowscriptaccess|width|height],iframe[src|frameborder|width|height],span[style],br');
                 $config->set('HTML.SafeObject', TRUE);
                 $config->set('HTML.SafeEmbed', TRUE);
                 $config->set('Output.FlashCompat', TRUE);
                 $config->set('AutoFormat.AutoParagraph', TRUE);
                 $config->set('AutoFormat.Linkify', TRUE);
                 // $config->set('AutoFormat.RemoveEmpty', TRUE);
                 $config->set('HTML.SafeIframe', true);
                 $config->set('URI.SafeIframeRegexp', '%^http://(www.youtube(?:-nocookie)?.com/embed/|player.vimeo.com/video/)%');
                 break;
             case FALSE:
                 $config = HTMLPurifier_Config::createDefault();
                 $config->set('Core.Encoding', 'utf-8');
                 $config->set('HTML.Doctype', 'XHTML 1.0 Strict');
                 break;
             default:
                 show_error('The HTMLPurifier configuration labeled "' . htmlentities($config, ENT_QUOTES, 'UTF-8') . '" could not be found.');
         }
         $purifier = new HTMLPurifier($config);
         $clean_html = $purifier->purify($dirty_html);
     }
     return $clean_html;
 }
Exemplo n.º 9
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     // Translation content HTML
     if ($request->has('translations')) {
         $merge = false;
         $translations = $request->input('translations');
         foreach ($translations as $locale => $translation) {
             if (!empty($translation['content'])) {
                 $translations[$locale]['content'] = html_purify($translation['content']);
                 $merge = true;
             }
         }
         if ($merge) {
             $request->merge(['translations' => $translations]);
         }
     }
     return $next($request);
 }
Exemplo n.º 10
0
 public function edit($id = 0)
 {
     $this->load->helper('form');
     $this->load->helper('htmlpurifier');
     $this->load->library('form_validation');
     $this->load->model('forums_m');
     $this->load->model('labels/labels_m');
     $this->form_validation->set_rules('name', 'Forum name', 'required|trim|htmlspecialchars|min_length[4]|xss_clean');
     $this->form_validation->set_rules('label', 'Label', 'required');
     if ($this->form_validation->run() == TRUE) {
         $data = array('name' => $this->input->post('name'), 'label' => $this->input->post('label'), 'clan' => $this->input->post('clan'), 'private' => $this->input->post('private'), 'description' => html_purify($this->input->post('description'), 'description'));
         $this->forums_m->update_forum($id, $data);
         $mods = $this->input->post('mods');
         $this->forums_m->add_moderators($mods, $id);
         redirect('admin/forums');
     } else {
         $this->template->set('title', 'Edit forum')->set('data', $this->forums_m->get_forum($id))->set('labels', $this->labels_m->get_all())->set('users', $this->ion_auth->users()->result())->build('admin/form');
     }
 }
Exemplo n.º 11
0
 function CreateOrUpdate()
 {
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('title', 'Event name', 'required');
     $this->form_validation->set_rules('event_date', 'Publishing Date', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("event_id") != NULL) {
             $this->secure_hard();
             $query = $this->db->get_where('events', array('id' => $this->input->get('event_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Event exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Event_form', $form_data);
         } else {
             $this->load->view('Event_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('user_id' => $this->session->userdata('user_id'), 'title' => html_purify($this->input->post('title')), 'description' => html_purify($this->input->post('description')), 'event_date' => html_purify($this->input->post('event_date')), 'school' => html_purify($this->input->post('school')), 'short_desc' => html_purify($this->input->post('short_desc')), 'image_path' => html_purify($this->input->post('image_path')), 'club' => html_purify($this->input->post('club')), 'type' => html_purify($this->input->post('type')));
         if ($this->input->get('event_id') != "") {
             // update
             $this->secure_hard();
             unset($form_data['user_id']);
             // remains original
             $this->db->update('events', $form_data, " id = '" . $this->input->get('event_id') . "'");
             $this->logger->insert('Updated event ' . html_purify($this->input->post('title')) . ' (' . $this->input->get('event_id') . ')');
         } else {
             $this->db->insert('events', $form_data);
             $this->logger->insert('Created event ' . html_purify($this->input->post('title')));
         }
         redirect(base_url() . 'Events/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 12
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('sc_name', 'School\'s name', 'required');
     $this->form_validation->set_rules('year', 'Year (Ex:2015)', 'required');
     $this->form_validation->set_rules('semester', 'Semester', 'required');
     $this->form_validation->set_rules('image_path', 'Document Location', 'required');
     $this->form_validation->set_rules('paper_name', 'Paper\'s name', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("exam_id") != NULL) {
             $query = $this->db->get_where('exams', array('id' => $this->input->get('exam_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Exam exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Exam_form', $form_data);
         } else {
             $this->load->view('Exam_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('sc_name' => html_purify($this->input->post('sc_name')), 'year' => html_purify($this->input->post('year')), 'semester' => html_purify($this->input->post('semester')), 'image_path' => html_purify($this->input->post('image_path')), 'paper_name' => html_purify($this->input->post('paper_name')));
         if ($this->input->get('exam_id') != "") {
             // update
             $this->db->update('exams', $form_data, " id = '" . $this->input->get('exam_id') . "'");
             $this->logger->insert('Updated exam paper - ' . html_purify($this->input->post('paper_name')) . ' (' . $this->input->get('exam_id') . ')');
         } else {
             $this->db->insert('exams', $form_data);
             $this->logger->insert('Created exam paper - ' . html_purify($this->input->post('paper_name')));
         }
         redirect(base_url() . 'Exams/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 13
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('sc_name', 'School\'s name', 'required');
     $this->form_validation->set_rules('book_name', 'Book\'s name', 'required');
     $this->form_validation->set_rules('dept_name', 'Department\'s name', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("ebook_id") != NULL) {
             $query = $this->db->get_where('ebooks', array('id' => $this->input->get('ebook_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Ebook exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Ebook_form', $form_data);
         } else {
             $this->load->view('Ebook_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('sc_name' => html_purify($this->input->post('sc_name')), 'dept_name' => html_purify($this->input->post('dept_name')), 'book_name' => html_purify($this->input->post('book_name')), 'book_info' => html_purify($this->input->post('book_info')), 'user_id' => $this->session->userdata('user_id'));
         if ($this->input->get('ebook_id') != "") {
             // update
             unset($form_data['user_id']);
             //keep original user
             $this->db->update('ebooks', $form_data, " id = '" . $this->input->get('ebook_id') . "'");
             $this->logger->insert('Updated ebook ' . html_purify($this->input->post('book_name')) . ' (' . $this->input->get('ebook_id') . ')');
         } else {
             $this->db->insert('ebooks', $form_data);
             $this->logger->insert('Created ebook ' . html_purify($this->input->post('book_name')));
         }
         redirect(base_url() . 'Ebooks/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 14
0
 public function create($sendtoID = 0)
 {
     $this->load->helper('form');
     $this->load->helper('htmlpurifier');
     $this->load->library('form_validation');
     $this->parser->checkFunctions();
     $this->form_validation->set_rules('title', 'Title', 'required|min_length[4]|trim|htmlspecialchars|xss_clean');
     $this->form_validation->set_rules('content', 'Content', 'required|min_length[4]|htmlspecialchars');
     $this->form_validation->set_rules('sendto', 'Send to', 'required|trim|htmlspecialchars|xss_clean');
     // TODO: Check username validation
     if ($this->form_validation->run() == TRUE) {
         if (empty($sendtoID)) {
             $sendtoID = get_user_id($this->input->post('sendto'));
         }
         $data = array('title' => $this->input->post('title'), 'content' => html_purify($this->input->post('content'), 'description'), 'to' => $sendtoID, 'from' => $this->user->id, 'date' => date('Y-m-d H:i:s'));
         $this->msg->insert($data);
         redirect('messages');
     } else {
         $this->load->model('users/users_m');
         $users = $this->users_m->get_all();
         $this->template->set('users', $users)->build('form.twig');
     }
 }
Exemplo n.º 15
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('program', 'Program\'s name', 'required');
     $this->form_validation->set_rules('semester', 'Semester', 'required');
     $this->form_validation->set_rules('branch', 'Branch', 'required');
     $this->form_validation->set_rules('subjects', 'Subjects', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("program_id") != NULL) {
             $query = $this->db->get_where('program_details', array('id' => $this->input->get('program_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Program exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Program_form', $form_data);
         } else {
             $this->load->view('Program_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('program' => html_purify($this->input->post('program')), 'semester' => html_purify($this->input->post('semester')), 'branch' => html_purify($this->input->post('branch')), 'subjects' => html_purify($this->input->post('subjects')));
         if ($this->input->get('program_id') != "") {
             // update
             $this->db->update('program_details', $form_data, " id = '" . $this->input->get('program_id') . "'");
             $this->logger->insert('Updated program - ' . $this->input->post('branch') . ' (' . $this->input->post('branch') . ') -' . $this->input->post('program') . ' (' . $this->input->get('program_id') . ')');
         } else {
             $this->db->insert('program_details', $form_data);
             $this->logger->insert('Created program - ' . $this->input->post('branch') . ' (' . $this->input->post('branch') . ') -' . $this->input->post('program'));
         }
         redirect(base_url() . 'Programs/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 16
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('title', 'Title', 'required');
     $this->form_validation->set_rules('link', 'Upload Path', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("notice_id") != NULL) {
             $query = $this->db->get_where('vnb', array('id' => $this->input->get('notice_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Notice exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Notice_form', $form_data);
         } else {
             $this->load->view('Notice_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('title' => html_purify($this->input->post('title')), 'date' => Date('Y-m-d'), 'link' => html_purify($this->input->post('link')), 'user_id' => $this->session->userdata('user_id'));
         if ($this->input->get('notice_id') != "") {
             // update
             unset($form_data['user_id']);
             unset($form_data['date']);
             $this->db->update('vnb', $form_data, " id = '" . $this->input->get('notice_id') . "'");
             $this->logger->insert('Updated notice - ' . html_purify($this->input->post('title')) . ' (' . $this->input->get('notice_id') . ')');
         } else {
             $this->db->insert('vnb', $form_data);
             $this->logger->insert('Created notice - ' . html_purify($this->input->post('title')));
         }
         redirect(base_url() . 'Notices/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 17
0
 public function edit($id = 0)
 {
     $this->load->helper('form');
     $this->load->library('form_validation');
     $this->load->library('upload');
     $this->load->helper('htmlpurifier');
     if ($this->form_validation->run('banners') == TRUE) {
         if (!empty($_FILES['image']['name'])) {
             $config['upload_path'] = $this->folder_path;
             $config['allowed_types'] = 'gif|jpg|png';
             $config['max_size'] = '0';
             $config['max_width'] = '0';
             $config['max_height'] = '0';
             $config['file_name'] = $id;
             $this->upload->initialize($config);
             if ($this->upload->do_upload('image')) {
                 $file_data = $this->upload->data();
             } else {
                 $this->session->set_flashdata('create_error', $this->upload->display_errors('', ''));
                 $file_data = NULL;
             }
         }
         // Found new file delete the old one
         $fileBanner = $this->banners_m->get($id)->image;
         if (!empty($file_data)) {
             unlink($this->folder_path . $fileBanner);
             $fileBanner = $file_data['file_name'];
         }
         $data = array('name' => $this->input->post('name'), 'width' => $this->input->post('width', TRUE), 'label' => $this->input->post('label'), 'height' => $this->input->post('height', TRUE), 'url' => urlencode($this->input->post('url')), 'date' => date('Y-m-d H:i:s'), 'description' => html_purify($this->input->post('description'), 'description'), 'code' => $this->input->post('code', TRUE), 'image' => $fileBanner);
         $this->banners_m->update($id, $data);
         redirect('admin/banners');
     } else {
         $this->load->model('labels/labels_m');
         $this->template->set('title', 'Edit banner')->set('data', $this->banners_m->as_array()->get($id))->set('labels', $this->labels_m->get_all())->build('admin/form');
     }
 }
Exemplo n.º 18
0
 public function edit($id = 0)
 {
     $this->load->helper('form');
     $this->load->library('form_validation');
     $this->load->library('upload');
     $this->load->helper('htmlpurifier');
     if ($this->form_validation->run('events') == TRUE) {
         if (!empty($_FILES['image']['name'])) {
             $config['upload_path'] = $this->folder_path;
             $config['allowed_types'] = 'gif|jpg|png';
             $config['max_size'] = '0';
             $config['max_width'] = '1000';
             $config['max_height'] = '1000';
             $config['file_name'] = $this->events_m->get_next_id();
             $this->upload->initialize($config);
             if ($this->upload->do_upload('image')) {
                 $file_data = $this->upload->data();
             } else {
                 $this->session->set_flashdata('create_error', $this->upload->display_errors('', ''));
                 $file_data = NULL;
             }
         }
         $fileImage = $this->events_m->get($id)->image;
         if (!empty($file_data)) {
             unlink($this->folder_path . $fileImage);
             $fileImage = $file_data['file_name'];
         }
         $startDate = $this->input->post('startdate') . ' ' . $this->input->post('starttime');
         $endDate = $this->input->post('enddate') . ' ' . $this->input->post('endtime');
         $data = array('name' => $this->input->post('name'), 'description' => html_purify($this->input->post('description'), 'description'), 'startdate' => $startDate, 'enddate' => $endDate, 'link' => $this->input->post('link'), 'image' => $fileImage);
         $this->events_m->update($id, $data);
         redirect('admin/events');
     } else {
         $this->template->set('title', 'Edit label')->set('data', $this->events_m->as_array()->get($id))->build('admin/form');
     }
 }
Exemplo n.º 19
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('room_no', 'Room Number', 'required');
     $this->form_validation->set_rules('rows', 'Rows', 'required');
     $this->form_validation->set_rules('columns', 'Columns', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("room_id") != NULL) {
             $query = $this->db->get_where('rooms', array('id' => $this->input->get('room_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Room exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Room_form', $form_data);
         } else {
             $this->load->view('Room_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('room_no' => html_purify($this->input->post('room_no')), 'rows' => html_purify($this->input->post('rows')), 'columns' => html_purify($this->input->post('columns')));
         if ($this->input->get('room_id') != "") {
             // update
             $this->db->update('rooms', $form_data, " id = '" . $this->input->get('room_id') . "'");
             $this->logger->insert('Updated room Number' . $this->input->post('room_no') . ' (' . $this->input->get('room_id') . ')');
         } else {
             $this->db->insert('rooms', $form_data);
             $this->logger->insert('Created room number - ' . $this->input->post('room_no'));
         }
         redirect(base_url() . 'Rooms/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 20
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('title', 'title', 'required');
     $this->form_validation->set_rules('slug', 'slug', 'required');
     $this->form_validation->set_rules('text', 'Description', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("news_id") != NULL) {
             $query = $this->db->get_where('news', array('id' => $this->input->get('news_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such News exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('News_form', $form_data);
         } else {
             $this->load->view('News_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $form_data = array('title' => html_purify($this->input->post('title')), 'slug' => html_purify($this->input->post('slug')), 'text' => html_purify($this->input->post('text')));
         if ($this->input->get('news_id') != "") {
             // update
             $this->db->update('news', $form_data, " id = '" . $this->input->get('news_id') . "'");
             $this->logger->insert('Updated news article - ' . html_purify($this->input->post('title')) . ' (' . $this->input->get('news_id') . ')');
         } else {
             $this->db->insert('news', $form_data);
             $this->logger->insert('Created news article - ' . html_purify($this->input->post('title')));
         }
         redirect(base_url() . 'News/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 21
0
 public function edit($id = 0)
 {
     $this->load->helper('form');
     $this->load->helper('htmlpurifier');
     $this->load->library('form_validation');
     $this->load->library('upload');
     $this->form_validation->set_rules('opponent', 'Opponent', 'required');
     $this->form_validation->set_rules('team', 'Team', 'required');
     $this->form_validation->set_rules('game', 'Game', 'required');
     $this->form_validation->set_rules('report', 'Report', 'required|min_length[4]');
     $this->form_validation->set_rules('date', 'Date', 'required|htmlspecialchars|trim|xss_clean');
     $this->form_validation->set_rules('time', 'Time', 'required|htmlspecialchars|trim|xss_clean');
     $this->form_validation->set_rules('matchlink', 'Match link', 'prep_url|htmlspecialchars|trim|xss_clean');
     $this->form_validation->set_rules('opponentscore', 'Opponent scores', 'xss_clean');
     $this->form_validation->set_rules('teamscore', 'Team scores', 'xss_clean');
     $this->form_validation->set_rules('opplayers', 'Opponent player list', 'trim|htmlspecialchars|xss_clean');
     if ($this->form_validation->run() == TRUE) {
         // Prep data
         $date = $this->input->post('date') . ' ' . $this->input->post('time');
         $players = $this->input->post('team_players');
         if (!empty($players)) {
             $team_players = implode(",", $players);
         } else {
             $team_players = NULL;
         }
         $data = array('team' => $this->input->post('team'), 'opponent' => $this->input->post('opponent'), 'date' => $date, 'game' => $this->input->post('game'), 'report' => html_purify($this->input->post('report'), 'wysiwyg'), 'type' => $this->input->post('type'), 'matchlink' => $this->input->post('matchlink'), 'status' => $this->input->post('status'), 'opponent-players' => $this->input->post('opplayers'), 'team-players' => $team_players, 'event' => $this->input->post('event'));
         $this->matches_m->update($id, $data);
         // Update scores
         $opponent_scores = $this->input->post('opponentscore', TRUE);
         $team_scores = $this->input->post('teamscore', TRUE);
         print_r($team_scores);
         $limit = count($team_scores);
         $score_array = array();
         for ($i = 0; $i < $limit; $i++) {
             $score_array[$i] = array('match' => $id, 'opponent' => intval($opponent_scores[$i]), 'team' => intval($team_scores[$i]));
         }
         $this->matches_m->update_scores($id, $score_array);
         // Delete screenshots
         $selectedScreenshots = $this->input->post('todelete');
         foreach ($selectedScreenshots as $screenShot) {
             // Found doomed screenshot
             if (strpos($screenShot, 'delete ') !== FALSE) {
                 $meta = explode(' ', $screenShot);
                 // Get filename
                 $this->matches_m->delete_screenshot($meta[1]);
                 // Finally delete the screenshot file
             }
         }
         // Update new screenshots
         if (!empty($_FILES['userfile']['name'][0])) {
             // Insert files
             // Process multiple file upload
             $files = $_FILES;
             $cpt = count($_FILES['userfile']['name']);
             for ($i = 0; $i < $cpt; $i++) {
                 $_FILES['userfile']['name'] = $files['userfile']['name'][$i];
                 $_FILES['userfile']['type'] = $files['userfile']['type'][$i];
                 $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$i];
                 $_FILES['userfile']['error'] = $files['userfile']['error'][$i];
                 $_FILES['userfile']['size'] = $files['userfile']['size'][$i];
                 $this->upload->initialize($this->set_upload_options($i, $id));
                 if ($this->upload->do_upload('userfile')) {
                     $file_data = $this->upload->data();
                     $this->matches_m->insert_files($id, $file_data['file_name']);
                 } else {
                     $this->session->set_flashdata('create_error', $_FILES['userfile']['name'] . ': ' . $this->upload->display_errors('', ''));
                     $file_data = NULL;
                 }
             }
         }
         redirect('admin/matches');
     } else {
         $this->load->model('opponents/opponents_m');
         $this->load->model('teams/teams_m');
         $this->load->model('games/games_m');
         $this->load->model('events/events_m');
         $this->template->set('title', 'Edit Match')->set('opponents', $this->opponents_m->get_all())->set('teams', $this->teams_m->get_all())->set('games', $this->games_m->get_all())->set('data', $this->matches_m->as_array()->get($id))->set('scores', $this->matches_m->get_scores($id))->set('screenshots', $this->matches_m->get_match_screenshots($id))->set('events', $this->events_m->get_all())->build('admin/form');
     }
 }
Exemplo n.º 22
0
	function chat_send(){
		$user_id = $this->session->userdata('user_id');
		$this->load->helper('htmlpurifier');
		if($id=$user_id){
			$msg = html_purify($this->input->post('message'));
			require_once(getcwd()."/application/helpers/pusher/Pusher.php");
			$pusher = new Pusher('deb0d323940b00c093ee', '9ab20336af22c4e7fa77', '25755');
			$data = array(
				'user_id' => $user_id,
				'username' => $this->view_data['me']['username'],
				'message' => $msg
			);
			$pusher->trigger('presence-chat-public', 'incomming-message', $data );
			echo $msg;
		}
	}
Exemplo n.º 23
0
 /**
  * @param $id - id of product
  */
 public function edit_product($id)
 {
     $id = $this->security->xss_clean($id);
     //data for the template
     $message = array('flashdata-error' => $this->session->flashdata('error-message'), 'flashdata' => $this->session->flashdata('message'));
     $this->smarty->assign('message', $message);
     $form = array('open' => form_open(site_url('cms/dashboard/edit_product') . '/' . $id, array('id' => 'edit-product-form')), 'close' => form_close());
     $this->smarty->assign('form', $form);
     $categories = $this->model_products->getCategories();
     $this->smarty->assign('categories', $categories);
     $product = $this->model_products->getProduct($id);
     //die_r($product);
     $this->smarty->assign('old_value', $product);
     //validation
     $this->form_validation->set_rules('cat_change', 'Category Change', 'xss_clean');
     $this->form_validation->set_rules('title', 'Product Title', 'trim|required|xss_clean');
     $this->form_validation->set_rules('description', 'Product Description', 'trim|required');
     $this->form_validation->set_rules('price', 'Price', 'trim|required|xss_clean|numeric|greater_than[0]');
     $this->form_validation->set_rules('visibility', 'Present on site', '');
     if ($this->form_validation->run() == false) {
         //set and assign values into smarty template
         $set_value = array('title' => set_value('title'), 'description' => set_value('description'), 'price' => set_value('price'));
         $this->smarty->assign('set_value', $set_value);
         $this->smarty->assign('validation_errors', validation_errors());
         //show input fields
         $this->data['content'] = $this->smarty->load('cms/editProduct', null, true);
         /* breadcrumbs */
         $this->breadcrumbs->unshift('Edit Product', site_url('cms/dashboard/edit_product/' . $id));
         $this->breadcrumbs->unshift('Admin Dashboard', site_url('cms/dashboard'));
         $this->load->view('cms/main', $this->data);
     } else {
         $this->post = $this->input->post();
         $this->post['id'] = $id;
         //clean a tinymce input by htmlpurifier
         $this->load->helper('htmlpurifier');
         $clean_html = html_entity_decode($this->input->post('description'));
         $clean_html = html_purify($clean_html, 'comment');
         $this->post['description'] = $clean_html;
         $this->post['cat_name'] = $product['cat_name'];
         $this->post['machine_name'] = $product['machine_name'];
         //change the visibility value
         if (isset($this->post['visibility'])) {
             $this->post['visibility'] = 1;
         } else {
             $this->post['visibility'] = 0;
         }
         $result = $this->model_cms->editProduct($this->post);
         if ($result) {
             $this->session->set_flashdata('message', 'The  "' . $this->post['title'] . '" was successfully updated!');
         } else {
             $this->session->set_flashdata('error-message', 'The product was not updated, any technical problem,try later');
         }
         redirect('cms/dashboard/edit_product/' . $id);
     }
 }
Exemplo n.º 24
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->library('form_validation');
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('username', 'Username', 'required');
     $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
     $this->form_validation->set_rules('full_name', 'Full Name', 'required');
     $this->form_validation->set_rules('username', 'Username', 'required|callback_check_username');
     $this->form_validation->set_rules('email', 'email', 'required|callback_check_email');
     $this->form_validation->set_rules('password', 'Password', 'callback_check_pass');
     $this->form_validation->set_rules('profile_picure', 'profile_picure', 'callback_check_image_and_upload');
     if ($this->form_validation->run() == FALSE) {
         $this->load->view('common/header');
         if ($this->input->get("user_id") != NULL) {
             $query = $this->db->get_where('users', array('user_id' => $this->input->get('user_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such user exists";
                 return;
             }
             $form_data = $query->row();
             $this->load->view('User_form', $form_data);
         } else {
             $this->load->view('User_form');
         }
         $this->load->view('common/footer');
     } else {
         $this->load->helper('htmlpurifier');
         $password = $this->input->post('password');
         $hash = $this->bcrypt->hash_password($password);
         $confirmation_link = bin2hex(openssl_random_pseudo_bytes(18));
         // 36 character lin
         $extra_log_message = NULL;
         $form_data = array('username' => html_purify($this->input->post('username')), 'email' => html_purify($this->input->post('email')), 'type' => html_purify($this->input->post('type')), 'password' => html_purify($this->input->post('password')), 'full_name' => html_purify($this->input->post('full_name')), 'roll_number' => html_purify($this->input->post('roll_number')), 'password' => $hash, 'confirmation_link' => $confirmation_link, 'profile_picture' => $this->image_path, 'active' => 1);
         if (strlen($this->image_path) == 0) {
             unset($form_data['profile_picture']);
         }
         if ($this->input->get('user_id') != "") {
             $query = $this->db->get_where('users', array('user_id' => $this->input->get('user_id')));
             $old_form_data = $query->row();
             $this->secure_post();
             if (strlen($password) == 0) {
                 // no change
                 unset($form_data['password']);
             } else {
                 $extra_log_message = $extra_log_message . ' + updated password ';
             }
             if ($form_data['type'] != $old_form_data->type) {
                 $extra_log_message = $extra_log_message . ' + Changed role to ' . $this->permissions->get_full_type($form_data['type']);
             } else {
                 unset($form_data['type']);
             }
             unset($form_data['confirmation_link']);
             //not needed
             $this->db->update('users', $form_data, " user_id = '" . $this->input->get('user_id') . "'");
             $this->logger->insert('Updated user - ' . html_purify($this->input->post('username')) . ' (' . $this->input->get('user_id') . ')' . $extra_log_message, TRUE, TRUE);
             if ($this->input->get('user_id') == $this->session->userdata('user_id')) {
                 redirect(base_url() . '/logout');
             }
         } else {
             $this->db->insert('users', $form_data, TRUE, TRUE);
         }
         redirect(base_url() . 'user_controls/view_all');
     }
 }
Exemplo n.º 25
0
 function CreateOrUpdate()
 {
     $this->secure_hard();
     $this->load->helper(array('form', 'url'));
     $this->form_validation->set_rules('date', 'Exam\'s Date', 'required');
     $this->form_validation->set_rules('shift', 'Shift', 'required');
     $this->form_validation->set_rules('time', 'time', 'required');
     $this->load->view('common/header');
     $this->load->library('form_validation');
     if ($this->form_validation->run() == FALSE) {
         if ($this->input->get("exam_id") != NULL) {
             $query = $this->db->get_where('exams', array('id' => $this->input->get('exam_id')));
             if ($query->num_rows() == 0) {
                 echo "<br /><br /><br /><br />No such Exam exists";
                 die;
             }
             $form_data = $query->row();
             $this->load->view('Exam_form', $form_data);
         } else {
             $this->load->view('Exam_form');
         }
     } else {
         $this->load->helper('htmlpurifier');
         $i = 1;
         $room_ids = '';
         $room_arr = array();
         /*
         * The following code is when rooms are mannually chosen
         * However currently all rooms are needed
         * 
          while (isset($_POST['room_' . $i])) {
          $room_ids .= $_POST['room_' . $i] . ' ';
         
          $q = $this->db->query("select * from rooms where id = '" . $_POST['room_' . $i] . " '");
          $res = $q->row();
          $room = new room($res->rows, $res->columns);
          $room->room_no = $res->room_no;
          array_push($room_arr, $room);
          $i++;
          }
         * 
         */
         $q = $this->db->query("select * from rooms");
         foreach ($q->result() as $res) {
             $room = new room($res->rows, $res->columns);
             $room->room_no = $res->room_no;
             array_push($room_arr, $room);
         }
         $master = array();
         $i = 1;
         $pg_sub_ids = '';
         $max_programs = $_POST['max_programs'];
         while ($i <= $max_programs) {
             if (!isset($_POST['subject_' . $i])) {
                 $i++;
                 continue;
             }
             $pg_sub_ids .= $_POST['program_' . $i] . ':' . $_POST['subject_' . $i] . ' ';
             $q = $this->db->query("select * from student_details where program_id = '" . $_POST['program_' . $i] . " '");
             $student_arr = array();
             foreach ($q->result() as $row) {
                 array_push($student_arr, $row->roll_no);
             }
             push_students($room_arr, $student_arr, $_POST['subject_' . $i], $master);
             echo $_POST['subject_' . $i] . '<br />';
             $i++;
         }
         $form_data = array('date' => html_purify($this->input->post('date')), 'shift' => html_purify($this->input->post('shift')), 'time' => html_purify($this->input->post('time')), 'pg_sub_ids' => $pg_sub_ids, 'room_ids' => $room_ids, 'arrangement_data' => serialize($room_arr), 'master' => serialize($master));
         if ($this->input->get('exam_id') != "") {
             // update
             if (strlen($room_ids) == 0 || strlen($pg_sub_ids) == 0) {
                 unset($form_data['pg_sub_ids']);
                 unset($form_data['room_ids']);
                 unset($form_data['arrangement_ids']);
                 unset($form_data['master']);
             }
             $this->db->update('exams', $form_data, " id = '" . $this->input->get('exam_id') . "'");
             $this->logger->insert('Updated exam - ' . $this->input->post('branch') . ' (' . $this->input->post('branch') . ') -' . $this->input->post('exam') . ' (' . $this->input->get('exam_id') . ')');
         } else {
             $this->db->insert('exams', $form_data);
             $this->logger->insert('Created exam - ' . $this->input->post('branch') . ' (' . $this->input->post('branch') . ') -' . $this->input->post('exam'));
         }
         redirect(base_url() . 'Exams/view_all');
     }
     $this->load->view('common/footer');
 }
Exemplo n.º 26
0
 public function edit($id = 0)
 {
     if ($this->user->id != $id) {
         redirect('profile/' . $id);
     }
     // Status messages
     $messages = array();
     // Load required classes
     $this->load->library('form_validation');
     $this->load->library('upload');
     $this->load->helper('form');
     $this->load->helper('htmlpurifier');
     // Add missing functions to twig parser
     $this->parser->checkFunctions();
     // Set validation rules
     $this->form_validation->set_rules('firstname', 'First name', 'trim|required|min_length[2]|max_length[20]');
     $this->form_validation->set_rules('dob', 'Date of birth', 'required');
     $this->form_validation->set_rules('gender', 'Gender', 'required');
     $this->form_validation->set_rules('country', 'Country', 'required');
     // Avatar file config
     $config['upload_path'] = $this->folder_path;
     $config['allowed_types'] = 'gif|jpg|png|bmp';
     $config['max_size'] = '1024';
     $config['max_width'] = '200';
     $config['max_height'] = '400';
     $config['file_name'] = $id;
     $this->upload->initialize($config);
     if ($this->form_validation->run()) {
         $dateDobPosted = $this->input->post('dob', TRUE);
         $dateDob = date('Y-m-d', strtotime($dateDobPosted));
         $data = array('first_name' => $this->input->post('firstname', TRUE), 'last_name' => $this->input->post('lastname', TRUE), 'dob' => $dateDob, 'gender' => $this->input->post('gender'), 'about' => html_purify($this->input->post('aboutme'), 'comment'), 'country' => $this->input->post('country'));
         // Upload the avatar
         $current_avatar = $this->ion_auth->user($id)->row()->avatar;
         if ($this->upload->do_upload('avatar')) {
             if (file_exists($this->folder_path . $current_avatar)) {
                 unlink($this->folder_path . $current_avatar);
             }
             $file_data = $this->upload->data();
             unset($current_avatar);
         } else {
             $file_data = NULL;
             $messages[] = $this->upload->display_errors();
         }
         // Check if avatar was indeed uploaded
         if (isset($file_data) and !empty($file_data['file_name'])) {
             $data['avatar'] = $file_data['file_name'];
         } else {
             $data['avatar'] = $current_avatar;
         }
         // Process account changes
         if ($this->input->post('newpassword') || $this->input->post('newmail')) {
             $currentPassword = $this->input->post('password', TRUE);
             if (!isset($currentPassword)) {
                 redirect('profile/' . $id);
             }
             $identity = $this->session->userdata($this->config->item('identity', 'ion_auth'));
             // Password change
             if ($this->input->post('newpassword')) {
                 $newPassword = $this->input->post('newpassword', TRUE);
                 if ($this->ion_auth->change_password($identity, $currentPassword, $newPassword)) {
                     $messages[] = 'Password change successful!';
                 } else {
                     $messages[] = $this->ion_auth->errors();
                 }
             }
             // Email change
             if ($this->input->post('newmail')) {
                 $this->load->helper('email');
                 $newMail = $this->input->post('newmail', TRUE);
                 if ($this->ion_auth->hash_password_db($id, $currentPassword) && valid_email($newMail)) {
                     $data['email'] = $newMail;
                     $messages[] = 'Email change successful!';
                 } else {
                     $messages[] = 'Unable to change email';
                 }
             }
         }
         $this->session->set_flashdata('profilemsgs', $messages);
         // Update!
         $this->ion_auth->update((int) $id, $data);
         redirect('profile/' . $id);
     } else {
         $this->template->set('data', $this->ion_auth->user($id)->row())->set('messages', $this->session->flashdata('profilemsgs'))->build('editprofile.twig');
     }
 }
Exemplo n.º 27
0
	private function bid_application(){
		$this->load->helper('htmlpurifier');
		$user_id = $this->session->userdata('user_id');
		$time = $this->input->post('time');
		$work_id = $this->input->post('work_id');
		$budget = $this->input->post('budget');
		$desc = html_purify($this->input->post('desc'));
		$arrangement = $this->work_model->get_work_arrangement($work_id);
		if(trim($desc)=="Ask a question or place your comment")$desc="";
		//save the bid in db
		$this->work_model->setBid($work_id,$user_id,$budget,$time,$desc);
		
		//save it in history
		$bid_id = $this->db->insert_id();
		$event='bid';
		$status = json_encode(array('bid_cost' => $budget,
			'bid_time' => $time,
			'bid_desc' => $desc,
			'work_id' => $work_id));
		$desc = "placed a bid";
		$this->work_model->log_history($user_id,$work_id,$event,$status,$desc);
		
		//push this event
		require_once(getcwd()."/application/helpers/pusher/Pusher.php");
		$bidpusher = new Pusher('deb0d323940b00c093ee', '9ab20336af22c4e7fa77', '25755');
		$data = array(
			'user_id' => $user_id,
			'user_level' => $this->game_model->get_level($this->view_data['me']['exp']),
			'username' => $this->view_data['me']['username'],
			'work_id' => $work_id,
			'time' => date('j M Y H:i'),
			'bid_id' => $bid_id,
			'bidget' => $budget,
			'time' => $time,
			'arrangement' => $arrangement
		);
		$bidpusher->trigger('bid', 'new-bid-'.$work_id, $data );
		
		//was user invited?
		$res = $this->work_model->invited_to_work($this->view_data['me']['user_id'],$work_id);
		if(count($res)){
			$this->work_model->updateInvite($res[0]['invite_id'],'accepted');
		}
		
		$res = array(
			'budget' => $budget,
			'time' => $time,
			'desc' => $desc,
			'username' => $this->view_data['me']['username'],
			'level' => $this->game_model->get_level($this->view_data['me']['exp']),
			'created_at' => date('Y-m-d H:i:s')
		);
		return $res;
	}