예제 #1
0
 public function index()
 {
     try {
         // If a logged in user type the login url then redirect him to the dashboard page.
         $login_status = $this->session->userdata("admin_loggedin");
         if (!empty($login_status)) {
             redirect(admin_base_url() . "dashboard/");
         }
         //Posted login form//
         if ($_POST) {
             $posted = array();
             $posted["txt_user_name"] = trim($this->input->post("txt_user_name"));
             $posted["txt_password"] = trim($this->input->post("txt_password"));
             $chk_remember = $this->input->post("chk_remember");
             $this->form_validation->set_rules('txt_user_name', 'user name', 'required');
             $this->form_validation->set_rules('txt_password', 'password', 'required');
             if ($this->form_validation->run() == FALSE) {
                 //Display the add form with posted values within it//
                 $this->data["posted"] = $posted;
             } else {
                 $this->load->model("User_login", "mod_ul");
                 $info = array();
                 $info["s_user_name"] = $posted["txt_user_name"];
                 $info["s_password"] = $posted["txt_password"];
                 // $loggedin=$this->mod_ul->login($info);
                 $loggedin = $this->mod_ul->backend_user_login($info);
                 if (!empty($loggedin)) {
                     $mix_data = $this->session->userdata('admin_loggedin');
                     if ($chk_remember) {
                         setcookie('acs_login_username', $info["s_user_name"], time() + 60 * 60 * 24 * 365, '/', '', '');
                         setcookie('acs_login_password', $info["s_password"], time() + 60 * 60 * 24 * 365, '/', '', '');
                     } else {
                         setcookie('acs_login_username', '', time() + 60 * 60 * 24 * 365, '/', '', '');
                         setcookie('acs_login_password', '', time() + 60 * 60 * 24 * 365, '/', '', '');
                     }
                     if (decrypt($mix_data['user_type']) != 0) {
                         set_success_msg(addslashes(t('Thanks for login ! Please change your current password')));
                     }
                     redirect(admin_base_url() . "dashboard/");
                 } else {
                     set_error_msg($this->cls_msg["invalid_login"]);
                     $this->data["posted"] = $posted;
                 }
             }
         }
         //end Posted login form//
         unset($loggedin);
         $this->render("index", true);
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }
예제 #2
0
 public function access_control($i_id = 0)
 {
     try {
         $this->data['heading'] = "Access control on " . ucwords($this->data['title']);
         /*don't change*/
         $this->data['pathtoclass'] = $this->pathtoclass;
         /*don't change*/
         $this->data['mode'] = "edit";
         /*don't change*/
         $user_type_id = decrypt($i_id);
         ////////////Submitted Form///////////
         if ($_POST) {
             $posted = array();
             //pr($_POST,1);
             $posted['opt_actions'] = $_POST['opt_actions'];
             $posted['h_action_permit'] = $_POST['h_action_permit'];
             //pr($posted['h_action_permit']);
             //pr($posted['opt_actions'],1);
             if (!empty($posted['h_action_permit'])) {
                 foreach ($posted['h_action_permit'] as $menu_id) {
                     $action = $posted['opt_actions'][$menu_id];
                     $assigned_link = $this->mod_menu->get_link_for_menu($menu_id, $user_type_id);
                     //pr($assigned_link);
                     //pr($action,1);
                     if (!empty($assigned_link)) {
                         foreach ($assigned_link as $key => $value) {
                             //echo ' ----'.in_array($key,$action);
                             if (!isset($action)) {
                                 $action = array();
                             }
                             if (!in_array($key, $action)) {
                                 $s_where = " WHERE s_link='" . $value . "' AND i_user_type=" . $user_type_id . " ";
                                 $i_aff = $this->mod_menu->delete_old_menu_permission($s_where);
                             }
                         }
                     }
                     if (!empty($action)) {
                         $all_link = $this->mod_menu->get_link_for_menu($menu_id);
                         foreach ($action as $value) {
                             if ($value != '' && !array_key_exists($value, $assigned_link)) {
                                 $info = array();
                                 $info['i_user_type'] = $user_type_id;
                                 $info['i_menu_id'] = $menu_id;
                                 $info['s_action'] = $value;
                                 $info['s_link'] = $all_link[$value];
                                 $i_aff = $this->mod_menu->add_menu_permit($info);
                             }
                         }
                     }
                 }
             }
             //$i_aff=$this->obj_mod->add_control($info,intval($i_user_type_id),intval($this->input->post("txt_controller_".strtolower($key))));/*don't change*/
             if ($i_aff) {
                 set_success_msg($this->cls_msg["save_succ"]);
                 /*don't change*/
                 redirect($this->pathtoclass . "access_control/" . $i_id);
                 /*don't change*/
             } else {
                 redirect($this->pathtoclass . "show_list");
                 /*don't change*/
                 //set_error_msg($this->cls_msg["save_err"]);/*don't change*/
             }
         } else {
             $user_type_id = decrypt($i_id);
             $info = $this->obj_mod->fetch_this_user($user_type_id);
             /*don't change*/
             $menu_action = $this->mod_menu->fetch_access_control($user_type_id);
             $this->data['menu_action'] = $menu_action;
             //pr($menu_action,1);
             unset($menu_action);
             //pr($this->data['s_menu']);
             $posted = array();
             $posted["h_mode"] = $this->data['mode'];
             /*don't change*/
             $posted["h_id"] = $i_id;
             /*don't change*/
             $posted["txt_user_type"] = trim($info["s_user_type"]);
             $this->data["posted"] = $posted;
             /*don't change*/
             unset($info, $posted);
             /*don't change*/
         }
         ////////////end Submitted Form///////////
         $this->render($this->router->fetch_class() . "/access-control");
         /*don't change*/
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }
예제 #3
0
 public function modify_information($i_id = 0)
 {
     $this->data['heading'] = t("Edit Information");
     $this->data['pathtoclass'] = $this->pathtoclass;
     $this->data['BREADCRUMB'] = array(addslashes(t('Edit Information')));
     $this->data['mode'] = 'edit';
     if ($_POST) {
         $posted = array();
         $posted["s_category"] = $this->input->post("s_category", true);
         $posted["s_category_description"] = $this->input->post("s_category_description", true);
         if (isset($_FILES['s_image']) && !empty($_FILES['s_image']['name'])) {
             $s_uploaded = get_file_uploaded(FCPATH . 'uploaded/category/', 's_image', '', '', 'jpeg|jpg|png|doc|docx|csv|xls|xlsx|pdf|txt');
             $arr_upload = explode('|', $s_uploaded);
         }
         if ($arr_upload[0] == 'ok') {
             $posted["s_image"] = $arr_upload[2];
         }
         $posted["s_date"] = $this->input->post("s_date", true);
         $posted["h_id"] = $this->input->post("h_id", true);
         $this->form_validation->set_rules('s_category', addslashes(t('category')), 'required|xss_clean');
         if ($this->form_validation->run() == FALSE) {
             /*if($arr_upload[0]==='err')
                   set_error_msg($arr_upload[2]);
               else
                   get_file_deleted($this->uploaddir,$arr_upload[2]);
               */
             //Display the add form with posted values within it//
             $this->data["posted"] = $posted;
         } else {
             $i_id = decrypt($posted["h_id"]);
             unset($posted["h_id"]);
             $i_aff = $this->acs_model->edit_data($this->tbl, $posted, array('i_id' => $i_id));
             if ($i_aff) {
                 /*
                 if($arr_upload[0]==='ok')
                 {
                     get_image_thumb($this->uploaddir.$posted["s_image"], $this->thumbdir, 'thumb_'.$posted["s_image"],$this->thumbHt,$this->thumbWd);
                 }
                 */
                 set_success_msg($this->cls_msg["save_succ"]);
                 redirect($this->pathtoclass . "show_list");
             } else {
                 set_error_msg($this->cls_msg["save_err"]);
             }
         }
     } else {
         // Fetch all the data
         $tmp = $this->acs_model->fetch_data($this->tbl, array('i_id' => decrypt($i_id)));
         $posted = $tmp[0];
         $posted['h_id'] = $i_id;
         $this->data['posted'] = $posted;
         $posted['h_mode'] = $this->data['mode'];
     }
     $this->render("category/add-edit");
 }
예제 #4
0
 public function modify_information($i_id = 0)
 {
     $this->data['heading'] = t("Edit Information");
     $this->data['pathtoclass'] = $this->pathtoclass;
     $this->data['BREADCRUMB'] = array(addslashes(t('Edit Information')));
     $this->data['mode'] = 'edit';
     if ($_POST) {
         $posted = array();
         $posted["s_name"] = $this->input->post("s_name", true);
         $posted["i_role"] = $this->input->post("i_role", true);
         $posted["i_status"] = $this->input->post("i_status", true);
         $posted["h_id"] = $this->input->post("h_id", true);
         $i_id = decrypt($posted["h_id"]);
         unset($posted["h_id"]);
         $i_aff = $this->acs_model->edit_data($this->tbl, $posted, array('i_id' => $i_id));
         if ($i_aff) {
             /*
             if($arr_upload[0]==='ok')
             {
                 get_image_thumb($this->uploaddir.$posted["s_image"], $this->thumbdir, 'thumb_'.$posted["s_image"],$this->thumbHt,$this->thumbWd);
             }
             */
             set_success_msg($this->cls_msg["save_succ"]);
             redirect($this->pathtoclass . "show_list");
         } else {
             set_error_msg($this->cls_msg["save_err"]);
         }
     } else {
         // Fetch all the data
         $tmp = $this->acs_model->fetch_data($this->tbl, array('i_id' => decrypt($i_id)));
         $posted = $tmp[0];
         $posted['h_id'] = $i_id;
         $this->data['posted'] = $posted;
         $posted['h_mode'] = $this->data['mode'];
     }
     $this->render("demo/add-edit");
 }
예제 #5
0
 public function generate()
 {
     try {
         // Get the database array
         require APPPATH . 'config/database.php';
         $existing_tables = array_slice($db['default'], 16);
         //$my_file = FCPATH.'application/config/database.php';
         //$handle = fopen($my_file, 'a');
         /*if ($handle) {
               $i = 1;
               while (($buffer = fgets($handle, 4096)) !== false) {
                   echo '<pre>'.$i++.$buffer.'</pre>';
               }
               if (!feof($handle)) {
                   echo "Error: unexpected fgets() fail\n";
               }
               fclose($handle);
           }*/
         //$filecontents = fgets($handle, 4096);
         //fseek($handle, 100);
         //fwrite($handle, "echo \"Yeah!\";\n");
         //fclose($handle);
         //$data = fread($handle, filesize($my_file));
         //pr($data);
         // Read the MySQL database
         $tables = $this->db->list_tables();
         $this->data['table_to_mvc'] = @array_diff($tables, $existing_tables);
         // Calulate the rest table to mvc
         if ($_POST) {
             $table_to_mvc = $this->input->post('opt_table', true);
             if ($table_to_mvc != '') {
                 $this->get_file_name($table_to_mvc);
                 $table_schema = $this->db->query("DESCRIBE {$table_to_mvc}")->result_array();
                 // pr($table_schema,1);
                 $con_c_field = '';
                 $con_c_validation = '';
                 $vw_c_field = '';
                 $vw_c_validation = '';
                 $width_percentage = ceil(100 / count($table_schema));
                 // As first field is autoincremented and primary field so escape it
                 for ($i = 1; $i < count($table_schema); $i++) {
                     // Define the field type and rest setting
                     $this->get_field_type($table_schema[$i]['Field'], $table_schema[$i]['Type']);
                     // Generate create/insert section  section for controller fields
                     if ($this->field_type == 'image_upload') {
                         $file_folder_name = FCPATH . 'uploaded/' . $this->folder_name;
                         if (!file_exists($file_folder_name)) {
                             mkdir($file_folder_name, 0777, true);
                             mkdir($file_folder_name . '/thumb', 0777, true);
                         }
                         $con_c_field .= "\n\n            if(isset(\$_FILES['{$table_schema[$i]['Field']}']) && !empty(\$_FILES['{$table_schema[$i]['Field']}']['name']))\n            {\n                \$s_uploaded = get_file_uploaded(FCPATH.'uploaded/{$this->folder_name}/','{$table_schema[$i]['Field']}','','','{$this->allowedExt}');        \n                \$arr_upload = explode('|',\$s_uploaded);    \n            }\n            if(\$arr_upload[0] == 'ok')\n                \$posted[\"{$table_schema[$i]['Field']}\"] = \$arr_upload[2];\n            ";
                     } else {
                         $con_c_field .= "\n\t\t\t\$posted[\"{$table_schema[$i]['Field']}\"] = \$this->input->post(\"{$table_schema[$i]['Field']}\", true);";
                     }
                     // Generate view field
                     $req_symbol = $this->required ? '*' : '';
                     $class = $i % 2 == 0 ? ' col-md-offset-2' : '';
                     if ($i % 2 != 0 && $i > 1) {
                         $vw_c_field .= "\n</div>\n<div class=\"row\">";
                     }
                     $display = '';
                     if ($this->field_type == 'image_upload') {
                         $display = "\n                            <?php  \n                                if(!empty(\$posted[\"s_image\"]))\n                                {\n                                    echo \"<img src='\".base_url('uploaded/" . $this->folder_name . "').'/'.\$posted[\"{$table_schema[$i]['Field']}\"].\"'  style='max-width:100px;max-height:100px;border:none;'/><br><br>\";\n                                    echo \"<input type='hidden' name='h_{$table_schema[$i]['Field']}' value='\".\$posted[\"{$table_schema[$i]['Field']}\"].\"' />\";\n                                }\n                            ?>";
                     }
                     $vw_c_field .= "\n\t" . sprintf(text_template($this->field_type), $class, $this->field_label, $req_symbol, $display, $table_schema[$i]['Field'], $table_schema[$i]['Field'], $table_schema[$i]['Field']);
                     if ($this->field_type == 'image_upload') {
                         $vw_details_field .= "\n\t\t\t<label class=\"col-md-4\"><?php echo addslashes(t('{$table_schema[$i]['Field']}'));?> : </label>\n\t\t\t<div class=\"col-md-8\"><p><img src=\"<?php echo base_url('uploaded/{$this->folder_name}').'/'.\$info[0]['{$table_schema[$i]['Field']}'];?>\" style=\"max-width:100px;max-height:100px;border:none\"/></p></div>\n\t\t\t<div class=\"clearfix\"></div>";
                     } else {
                         $vw_details_field .= "\n\t\t\t<label class=\"col-md-4\"><?php echo addslashes(t('{$table_schema[$i]['Field']}'));?> : </label>\n\t\t\t<div class=\"col-md-8\"><p><?php echo \$info[0]['{$table_schema[$i]['Field']}']; ?></p></div>\n\t\t\t<div class=\"clearfix\"></div>";
                     }
                     // Generate the form validation rule
                     if ($this->required) {
                         $this->con_form_validation .= "\n\t\t\t\$this->form_validation->set_rules('{$table_schema[$i]['Field']}', addslashes(t('" . strtolower($this->field_label) . "')), 'required|xss_clean');";
                         $this->vw_form_validation .= "\n\t\tif(\$(\"#{$table_schema[$i]['Field']}\").val()=='')\n\t\t{\n\t\t\tmarkAsError(\$(\"#{$table_schema[$i]['Field']}\"),'<?php echo addslashes(t(\"Please provide " . strtolower($this->field_label) . "\"))?>');\n\t\t\tb_valid = false;\n\t\t}";
                     }
                     // Generate search field
                     if ($this->field_type == 'text' && $this->search_field_added == false) {
                         $con_search_field = "\n\t\t\t\$search_variable[\"{$table_schema[$i]['Field']}\"] = (\$this->input->post(\"h_search\")?\$this->input->post(\"{$table_schema[$i]['Field']}\"):\$arr_session_data[\"{$table_schema[$i]['Field']}\"]);";
                         $con_search_inner_field = "\n\t\t\t\tif(\$search_variable[\"{$table_schema[$i]['Field']}\"]!=\"\")\n\t\t\t\t{\n\t\t\t\t\t\$s_where .= \" AND n.{$table_schema[$i]['Field']} LIKE '%\".addslashes(\$search_variable[\"{$table_schema[$i]['Field']}\"]).\"%' \";\n\t\t\t\t}\n\t\t\t\t\$arr_session[\"{$table_schema[$i]['Field']}\"] = \$search_variable[\"{$table_schema[$i]['Field']}\"];\n\t\t\t\t\$this->data[\"{$table_schema[$i]['Field']}\"] = \$search_variable[\"{$table_schema[$i]['Field']}\"];";
                         $vw_search_field = "\t\t\t\t\t\t\t\t<div class=\"form-group\">\n\t\t\t\t\t\t\t\t\t<label class=\"\"><?php echo addslashes(t(\"{$this->field_label}\"))?></label>\n\t\t\t\t\t\t\t\t\t<input type=\"text\" name=\"{$table_schema[$i]['Field']}\" id=\"{$table_schema[$i]['Field']}\" value=\"<?php echo \${$table_schema[$i]['Field']}?>\" class=\"form-control\" />\n\t\t\t\t\t\t\t\t</div>";
                         $search_field = $table_schema[$i]['Field'];
                         $this->search_field_added = true;
                     }
                     // Generate show list view
                     $con_show_list_header .= "\n\t\t\t\$table_view[\"headers\"][++\$j][\"width\"] = \"{$width_percentage}%\";\n\t\t\t\$table_view[\"headers\"][\$j][\"align\"] = \"left\";\n\t\t\t\$table_view[\"headers\"][\$j][\"val\"] = addslashes(t(\"{$this->field_label}\"));";
                     if ($this->field_type == 'image_upload') {
                         $con_show_list_view .= "\n\t\t\t\t\$table_view[\"tablerows\"][\$i][\$i_col++] = \"<img src='\".base_url('uploaded/{$this->folder_name}').\"/\".\$info[\$i][\"{$table_schema[$i]['Field']}\"].\"' style='max-width:80px; max-height:80px;' alt='{$this->field_label}'/>\";";
                     } else {
                         $con_show_list_view .= "\n\t\t\t\t\$table_view[\"tablerows\"][\$i][\$i_col++] = \$info[\$i][\"{$table_schema[$i]['Field']}\"];";
                     }
                     unset($this->required, $class, $this->field_type, $req_symbol, $this->field_label);
                 }
                 // Write on file
                 ##--------------------------------------------------------------------------------------##
                 ##  Write script to the controller                                                      ##
                 ##--------------------------------------------------------------------------------------##
                 // Generate the controller file (Path to controller)
                 $this->controller_file = FCPATH . 'application/controllers/' . $this->admin_folder_name . $this->file_name . '.php';
                 $controller = "<?php \n\n/***\n";
                 $controller .= $this->generate_file_info($this->file_name . '.php');
                 $controller .= "class " . ucfirst($this->file_name) . " extends MY_Controller \n{";
                 // Add class name
                 $controller .= $this->generate_contruct($table_to_mvc);
                 // Generate show_list method
                 $controller .= "\n\n    /****\n    * Display the list of records \n    */\n    public function show_list(\$start = NULL, \$limit = NULL)\n    {\n        try\n        {\n            \$this->data['heading'] = addslashes(t(\"{$this->mvc_title}\")); //Package Name[@package] Panel Heading\n            \n            //generating search query//\n            \$arr_session_data = \$this->session->userdata(\"arr_session\");\n            if(\$arr_session_data['searching_name'] != \$this->data['heading'])\n            {\n                \$this->session->unset_userdata(\"arr_session\");\n                \$arr_session_data = array();\n            }\n            \n            \$search_variable = array();\n            //Getting Posted or session values for search//        \n            \$s_search = (isset(\$_POST[\"h_search\"])?\$this->input->post(\"h_search\"):\$this->session->userdata(\"h_search\"));{$con_search_field}\n            //end Getting Posted or session values for search//            \n            \n            \$s_where = \" n.i_id != 0 \";\n            if(\$s_search == \"advanced\")\n            {\n                \$arr_session = array();\n                \$arr_session[\"searching_name\"] = \$this->data['heading'];\n                {$con_search_inner_field}\n                \$this->session->set_userdata(\"arr_session\",\$arr_session);\n                \$this->session->set_userdata(\"h_search\",\$s_search);\n                \$this->data[\"h_search\"] = \$s_search;                            \n            }\n            else //List all records, **not done\n            {\n                //Releasing search values from session//\n                \$this->session->unset_userdata(\"arr_session\");\n                \$this->session->unset_userdata(\"h_search\");\n                \n                \$this->data[\"h_search\"] = \$s_search;\n                \$this->data[\"{$search_field}\"] = ''; \n                //end Storing search values into session//                 \n            }\n            unset(\$s_search,\$arr_session,\$search_variable);\n            \n            //Setting Limits, If searched then start from 0//\n            \$start = \$this->input->post(\"h_search\") ? 0 : \$this->uri->segment(\$this->i_uri_seg);\n            //end generating search query//\n            \n            \$limit = \$this->i_admin_page_limit;\n            \$info = \$this->acs_model->fetch_data(\$this->tbl.' AS n', \$s_where, '', intval(\$start), \$limit);\n            \n            //Creating List view for displaying//\n            \$table_view = array();  \n            \n            //Table Headers, with width,alignment//\n            \$table_view[\"caption\"]                 = addslashes(t(\"{$this->mvc_title}\"));\n            \$table_view[\"total_rows\"]              = count(\$info);\n            \$table_view[\"total_db_records\"]        = \$this->acs_model->count_info(\$this->tbl.' AS n', \$s_where, 'n.');\n            \$table_view[\"detail_view\"]             = false;  // to disable show details. \n            \$j = -1;\n            {$con_show_list_header}\n            //end Table Headers, with width,alignment//\n            \n            //Table Data//\n            for(\$i = 0; \$i< \$table_view[\"total_rows\"]; \$i++)\n            {\n                \$i_col = 0;\n                \$table_view[\"tablerows\"][\$i][\$i_col++] = encrypt(\$info[\$i][\"i_id\"]);                \n                {$con_show_list_view}\n            } \n            //end Table Data//\n            unset(\$i, \$i_col, \$start, \$limit, \$s_where); \n            \n            \$this->data[\"table_view\"] = \$this->admin_showin_table(\$table_view,TRUE);\n   \n            //Creating List view for displaying//\n            \$this->data[\"search_action\"] = \$this->pathtoclass.\$this->router->fetch_method();//used for search form action\n            \n            \$this->render();          \n            unset(\$table_view, \$info);\n        }\n        catch(Exception \$err_obj)\n        {\n            show_error(\$err_obj->getMessage());\n        }          \n    }\n";
                 // Generate add_information method
                 $controller .= "\n \n    /***\n    * Method to Display and Save New information\n    * This have to sections: \n    *  >>Displaying Blank Form for new entry.\n    *  >>Saving the new information into DB\n    * After Posting the form, the posted values must be\n    * shown in the form if any error occurs to avoid re-entry of the form.\n    * \n    * On Success redirect to the showList interface else display error here.\n    */\n    public function add_information()\n    {\n        \$this->data['heading'] = (t(\"Add Information\"));\n        \$this->data['pathtoclass'] = \$this->pathtoclass;\n        \$this->data['BREADCRUMB'] = array(addslashes(t('Add Information')));\n        \$this->data['mode'] = 'add';\n        \n        if(\$_POST)\n        {\n            \$posted = array();\n            " . $con_c_field . " ";
                 if ($this->con_form_validation != '') {
                     $controller .= $this->con_form_validation;
                     $controller .= "\n            if(\$this->form_validation->run() == FALSE /*|| \$arr_upload[0]==='err'*/)//invalid\n            {\n                /*if(\$arr_upload[0]==='err')\n                    set_error_msg(\$arr_upload[2]);\n                else\n                    get_file_deleted(\$this->uploaddir,\$arr_upload[2]);\n                */\n                //Display the add form with posted values within it//\n                \$this->data[\"posted\"] = \$posted;\n            }\n            else//validated, now save into DB\n            {\n                ";
                 }
                 $controller .= "\n                \$i_newid = \$this->acs_model->add_data(\$this->tbl, \$posted);\n                if(\$i_newid)//saved successfully\n                {\n                    /*\n                    if(\$arr_upload[0]==='ok')\n                    {\n                        get_image_thumb(\$this->uploaddir.\$posted[\"s_image\"], \$this->thumbdir, 'thumb_'.\$posted[\"s_image\"],\$this->thumbHt,\$this->thumbWd);\n                    }\n                    */\n                    set_success_msg(\$this->cls_msg[\"save_succ\"]);\n                    redirect(\$this->pathtoclass.\"show_list\");\n                }\n                else//Not saved, show the form again\n                {\n                    set_error_msg(\$this->cls_msg[\"save_err\"]);\n                }";
                 if ($this->con_form_validation != '') {
                     $controller .= "\n\t\t\t}";
                 }
                 $controller .= "\n        }\n        //end Submitted Form//\n        \n        \$this->render(\"{$this->folder_name}/add-edit\");\n    }";
                 // Generate modify_information method
                 $controller .= "\n\n    /***\n    * Method to Display and Save Updated information\n    * This have to sections: \n    *  >>Displaying Values in Form for modifying entry.\n    *  >>Saving the new information into DB    \n    * After Posting the form, the posted values must be\n    * shown in the form if any error occurs to avoid re-entry of the form.\n    * \n    * On Success redirect to the showList interface else display error here. \n    * @param int \$i_id, id of the record to be modified.\n    */\n    public function modify_information(\$i_id=0)\n    {\n        \$this->data['heading'] = (t(\"Edit Information\"));\n        \$this->data['pathtoclass'] = \$this->pathtoclass;\n        \$this->data['BREADCRUMB'] = array(addslashes(t('Edit Information')));\n        \$this->data['mode'] = 'edit';\n        \n        if(\$_POST)\n        {\n            \$posted = array();\n        " . $con_c_field;
                 $controller .= "\n\n            \$posted[\"h_id\"] = \$this->input->post(\"h_id\", true);";
                 if ($this->con_form_validation != '') {
                     $controller .= $this->con_form_validation;
                     $controller .= "\n            if(\$this->form_validation->run() == FALSE /*|| \$arr_upload[0]==='err'*/)//invalid\n            {\n                /*if(\$arr_upload[0]==='err')\n                    set_error_msg(\$arr_upload[2]);\n                else\n                    get_file_deleted(\$this->uploaddir,\$arr_upload[2]);\n                */\n                //Display the add form with posted values within it//\n                \$this->data[\"posted\"] = \$posted;\n            }\n            else//validated, now save into DB\n            {\n                ";
                 }
                 $controller .= "\n                \$i_id = decrypt(\$posted[\"h_id\"]);\n                unset(\$posted[\"h_id\"]);\n                \$i_aff = \$this->acs_model->edit_data(\$this->tbl,\$posted, array('i_id'=>\$i_id));\n                if(\$i_aff)//saved successfully\n                {\n                    /*\n                    if(\$arr_upload[0]==='ok')\n                    {\n                        get_image_thumb(\$this->uploaddir.\$posted[\"s_image\"], \$this->thumbdir, 'thumb_'.\$posted[\"s_image\"],\$this->thumbHt,\$this->thumbWd);\n                    }\n                    */\n                    set_success_msg(\$this->cls_msg[\"save_succ\"]);\n                    redirect(\$this->pathtoclass.\"show_list\");\n                }\n                else//Not saved, show the form again\n                {\n                    set_error_msg(\$this->cls_msg[\"save_err\"]);\n                }";
                 if ($this->con_form_validation != '') {
                     $controller .= "\n\t\t\t}";
                 }
                 $controller .= "\n        }//end Submitted Form//\n        else\n        {\n            // Fetch all the data\n            \$tmp = \$this->acs_model->fetch_data(\$this->tbl,array('i_id'=>decrypt(\$i_id)));\n            \$posted = \$tmp[0];\n            \$posted['h_id'] = \$i_id;\n            \$this->data['posted'] = \$posted;\n            \$posted['h_mode'] = \$this->data['mode'];\n        }\n        \n        \$this->render(\"{$this->folder_name}/add-edit\");\n    }";
                 // Generate view_detail method
                 $controller .= "\n\n    /***\n    * Shows details of a single record.\n    * \n    * @param int \$i_id, Primary key\n    */\n    public function view_detail(\$i_id = 0)\n    {\n        try\n        {\n            if(!empty(\$i_id))\n            {\n                \$this->data[\"info\"] = \$this->acs_model->fetch_data(\$this->tbl,array('i_id'=>\$i_id));\n            }\n            \$this->load->view('{$this->admin_folder_name}{$this->folder_name}/show_detail.tpl.php', \$this->data); \n        }\n        catch(Exception \$err_obj)\n        {\n            show_error(\$err_obj->getMessage());\n        }         \n    }";
                 // Generate ajax_remove_information method
                 $controller .= "\n\n    /***\n    * Method to Delete information\n    * This have no interface but db operation \n    * will be done here.\n    * \n    * On Success redirect to the showList interface else display error in showList interface. \n    * @param int \$i_id, id of the record to be modified.\n    */  \n    public function ajax_remove_information()\n    {\n        try\n        {\n            \$i_id = decrypt(\$this->input->post(\"temp_id\"));\n            echo \$this->acs_model->delete_data(\$this->tbl, array('i_id'=>\$i_id)) ? 'ok' : 'error';\n            unset(\$i_id);\n        }\n        catch(Exception \$err_obj)\n        {\n            show_error(\$err_obj->getMessage());\n        }         \n    }";
                 $controller .= $this->generate_destruct();
                 $controller .= "\n}";
                 file_put_contents($this->controller_file, $controller);
                 ##--------------------------------------------------------------------------------------##
                 ##  End COntroller section                                                              ##
                 ##--------------------------------------------------------------------------------------##
                 ##--------------------------------------------------------------------------------------##
                 ##  Write script to the view                                                            ##
                 ##--------------------------------------------------------------------------------------##
                 mkdir(FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name);
                 // Generate the view file for show_list.tpl.php  (Path to view)
                 $this->show_list_view_file = FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name . '/show_list.tpl.php';
                 $show_list_view = "<?php \n\n/***\n";
                 $show_list_view .= $this->generate_file_info($this->file_name . " show_list.tpl.php") . "\n?>";
                 $show_list_view .= "\n<script>var g_controller=\"<?php echo \$pathtoclass;?>\", search_action = '<?php echo \$search_action;?>';// Controller Path </script>";
                 $show_list_view .= "\n<script src=\"<?php echo base_url()?>resource/admin/js/custom_js/add_edit_view.js\" type=\"text/javascript\"></script>";
                 $show_list_view .= "\n\n<div class=\"container-fluid\">\n    <div class=\"row\">\n        <div class=\"col-md-10 col-md-offset-1\">\n            <div class=\"row\">\n                <div class=\"col-md-8 col-md-offset-2\">\n        \n                    <div class=\"box-header well\">\n                        <h2><?php echo addslashes(t(\"Search\"))?></h2>             \n                    </div>\n    \n                    <?php show_all_messages(); ?>\n                    <form class=\"form-horizontal\" id=\"frm_search_3\" name=\"frm_search_3\" method=\"post\" action=\"<?php echo \$search_action?>\" >\n                        <input type=\"hidden\" id=\"h_search\" name=\"h_search\" value=\"\" />    \n                    </form>\n            \n                    <form class=\"\" id=\"frm_search_2\" name=\"frm_search_2\" method=\"post\" action=\"\" >\n                        <input type=\"hidden\" id=\"h_search\" name=\"h_search\" value=\"advanced\" />        \n                        <div id=\"div_err_2\"></div>        \n                        <div class=\"row\">\n                            <div class=\"col-md-5\">\n                            {$vw_search_field}\n                            </div>\n                        </div>\n                        <div class=\"form-group\">\n                            <button type=\"button\" search=\"2\" id=\"btn_submit\" name=\"btn_submit\" class=\"btn btn-primary\"><?php echo addslashes(t(\"Search\"))?></button>                 \n                            <button type=\"button\" id=\"btn_srchall\" name=\"btn_srchall\" class=\"btn\"><?php echo addslashes(t(\"Show All\"))?></button>\n                        </div>\n                    </form>  \n                </div>\n            </div>\n\n            <?php echo \$table_view;?><!-- content ends -->\n        </div>\n    </div>\n</div>\n";
                 file_put_contents($this->show_list_view_file, $show_list_view);
                 // Write add-edit.tpl.php
                 // Generate the view file for add-edit.tpl.php  (Path to view)
                 $this->view_file = FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name . '/add-edit.tpl.php';
                 $view = "<?php \n\n/***\n";
                 $view .= $this->generate_file_info($this->file_name . " add-edit.tpl.php") . "\n?>";
                 $view .= "\n<script>var g_controller=\"<?php echo \$pathtoclass;?>\", search_action = '<?php echo \$search_action;?>';// Controller Path </script>";
                 $view .= "\n<script src=\"<?php echo base_url()?>resource/admin/js/custom_js/add_edit_view.js\" type=\"text/javascript\"></script>";
                 // Generate the javascript form validation
                 if ($this->vw_form_validation != '') {
                     /*$view_javascript_file = FCPATH.'resource/admin/js/custom_js/'.$this->file_name.'.js';
                       $view .= "\n<script src=\"<?php echo base_url()?>resource/admin/js/custom_js/{$this->file_name}.js\" type=\"text/javascript\"></script>\n";*/
                     $view .= "\n<script type\"text/javascript\">\n\$(document).ready(function(){\n    //Submitting the form//\n    \$(\"#frm_add_edit\").submit(function(){\n        var b_valid=true;\n        var s_err='';\n        \$(\"#div_err\").hide(\"slow\");\n        {$this->vw_form_validation}\n        //validating//\n        if(!b_valid)\n        {        \n            \$(\"#div_err\").html('<div id=\"err_msg\" class=\"error_massage\">'+s_err+'</div>').show(\"slow\");\n        }\n    \n        return b_valid;\n    });\n});\n</script>";
                     //file_put_contents($view_javascript_file, $js);
                 }
                 $view .= "\n<div class=\"container-fluid\">\n    <div class=\"row\">\n        <div class=\"col-md-10 col-md-offset-1\">\n            <div class=\"box-header\">\n                <h3 class=\"box-title\"><?php echo \$heading;?></h3>\n            </div><!-- /.box-header -->\n            \n            <!-- form start -->\n            <?php show_all_messages();?>\n            <form role=\"form\" id=\"frm_add_edit\" name=\"frm_add_edit\" action=\"\" method=\"post\" autocomplete=\"off\"  enctype=\"multipart/form-data\">\n                <input type=\"hidden\" id=\"h_id\" name=\"h_id\" value=\"<?php echo \$posted[\"h_id\"];?>\">\n                <div class=\"row\">\n                " . $vw_c_field . "\n                </div>\n                \n                <div class=\"form-group\">\n                    <input type=\"button\" id=\"btn_save\" name=\"btn_save\" class=\"btn btn-primary\" value=\"<?php echo addslashes(t(\"Save changes\"))?>\">\n                    <input type=\"button\" id=\"btn_cancel\" name=\"btn_cancel\" class=\"btn\" value=\"<?php echo addslashes(t(\"Cancel\"))?>\">\n                </div>\n            </form>\n        </div>\n    </div><!--/row-->\n</div><!-- content ends -->\n";
                 file_put_contents($this->view_file, $view);
                 // Write add-edit.tpl.php
                 // Generate view for view_detail.tpl.php
                 $view_detail_view_file = FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name . '/view_detail.tpl.php';
                 $view_detail_view = "<?php \n\n/***\n";
                 $view_detail_view .= $this->generate_file_info($this->file_name . " view_detail.tpl.php") . "\n?>";
                 $view_detail_view .= "\n\n<div id=\"content\" class=\"\" style=\"max-height:500px; width:700px;overflow-x:hidden; overflow-y:scroll;\">\n   <div class=\"container-fluid\">\n      <h2><?php echo addslashes(t('View Detail'))?></h2>    \n              \n      <div class=\"row\">\n      {$vw_details_field}\n      </div>\n   </div>\n</div>\n";
                 file_put_contents($view_detail_view_file, $view_detail_view);
                 // Write view_detail.tpl.php file
                 ##--------------------------------------------------------------------------------------##
                 ##  End View Section                                                                    ##
                 ##--------------------------------------------------------------------------------------##
                 // Update the table name to the config/database.php file
                 set_success_msg('MVC has been generated successfully');
                 unset($this->con_form_validation, $this->vw_form_validation);
             }
         }
         $this->render();
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }
예제 #6
0
 public function menu_permission($enc_menu_id = '')
 {
     //echo 'politique de confidentialit&eacute;';
     try {
         $this->data['title'] = "Menu setting";
         //Browser Title
         $this->data['heading'] = "Menu Permission";
         $this->data['pathtoclass'] = $this->pathtoclass;
         $this->data['mode'] = "add";
         $i_menu_id = decrypt($enc_menu_id);
         //Submitted Form//
         if ($_POST) {
             $posted = array();
             $posted['txt_action'] = $this->input->post('txt_action');
             $posted['txt_link'] = $this->input->post('txt_link');
             $posted['h_id'] = $this->input->post('h_id');
             $posted['txt_extra_action'] = $this->input->post('txt_extra_action');
             $data = array();
             $s_actions = '';
             if (!empty($posted['txt_action'])) {
                 foreach ($posted['txt_action'] as $key => $val) {
                     if ($val != '') {
                         $s_actions .= $val . '||';
                         $data[$key]['s_action'] = $val;
                         $data[$key]['s_link'] = $posted['txt_link'][$key];
                         $data[$key]['h_id'] = $posted['h_id'][$key];
                     }
                 }
             }
             if (!empty($posted['txt_extra_action'])) {
                 foreach ($posted['txt_extra_action'] as $val) {
                     $s_actions .= $val . '||';
                 }
             }
             $s_actions = rtrim($s_actions, '|');
             //pr($data,1);
             // Edit menu table set all action like Add ||  Edit || Status
             $this->mod_menu->edit_info(array('s_action_permit' => $s_actions), $i_menu_id);
             $info = array();
             if (!empty($data)) {
                 $info['i_menu_id'] = $i_menu_id;
                 $info['i_user_type'] = 0;
                 foreach ($data as $val) {
                     $info['s_action'] = $val['s_action'];
                     $info['s_link'] = $val['s_link'];
                     if ($val['h_id'] == -1) {
                         $i_aff = $this->mod_menu->add_menu_permit($info);
                     } else {
                         $i_aff = $this->mod_menu->edit_menu_permit($info, $val['h_id']);
                     }
                 }
             }
             if ($i_aff) {
                 //saved successfully
                 set_success_msg($this->cls_msg["save_succ_permit"]);
                 redirect($this->pathtoclass . "menu_permission/" . $enc_menu_id);
             } else {
                 //Not saved, show the form again
                 set_error_msg($this->cls_msg["save_err_permit"]);
             }
         } else {
             $s_where = " WHERE i_menu_id=" . decrypt($enc_menu_id) . " AND (i_user_type=0 OR i_user_type=-99)";
             $info = $this->mod_menu->fetch_menu_permission($s_where);
             $actions = array();
             $temp_action = array();
             if (!empty($info)) {
                 foreach ($info as $key => $val) {
                     $temp_action[] = $val['s_action'];
                     $actions[$key]['txt_action'] = $val['s_action'];
                     $actions[$key]['txt_link'] = $val['s_link'];
                     $actions[$key]['h_id'] = $val['id'];
                 }
             }
             $this->data['actions'] = json_encode($actions);
             $info_menu = $this->mod_menu->fetch_this($i_menu_id);
             $all_action = explode('||', $info_menu['s_action_permit']);
             $this->data['extra_action'] = array_diff($all_action, $temp_action);
             unset($all_action, $temp_action, $info_menu, $actions);
             $s_where = " WHERE i_id=" . decrypt($enc_menu_id) . " ";
             $info_menu = $this->mod_menu->fetch_sub_menu($s_where);
             if (!empty($info_menu) && count($info_menu) == 1) {
                 preg_match('~^(.*\\/).*~', $info_menu[0]['s_link'], $matches);
                 $this->data['controler_link'] = $matches[1];
             }
         }
         $this->data['i_menu_id'] = decrypt($enc_menu_id);
         $this->data['BREADCRUMB'] = array(addslashes('Menu Permission'));
         /* $this->data['arr_status'] =   array(0=>'Keep',1=>'Add'); */
         $this->data['posted'] = $posted;
         //end Submitted Form//
         $this->render("menu_setting/menu_permission");
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }
예제 #7
0
 public function account_information($i_id)
 {
     try {
         $this->data['title'] = addslashes(t("Edit Account Details"));
         $this->data['heading'] = addslashes(t("Edit Account"));
         $this->data['pathtoclass'] = $this->pathtoclass;
         $loggedin = $this->session->userdata('admin_loggedin');
         // check if the user only can edit his information or super admin can do it
         redirect($this->pathtoclass);
         $arr_where = array('i_id' => decrypt($i_id));
         ////////////Submitted Form///////////
         if ($_POST) {
             $posted = array();
             $posted["s_first_name"] = trim($this->input->post("s_first_name"));
             $posted["s_last_name"] = trim($this->input->post("s_last_name"));
             $posted["s_email"] = trim($this->input->post("s_email"));
             $posted["s_address"] = trim($this->input->post("s_address"));
             $posted["s_contact_number"] = trim($this->input->post("s_contact_number"));
             $this->form_validation->set_rules('s_first_name', addslashes(t('first name')), 'required');
             $this->form_validation->set_rules('s_last_name', addslashes(t('last name')), 'required');
             $this->form_validation->set_rules('s_email', addslashes(t('Email')), 'required');
             if ($this->form_validation->run() == FALSE) {
                 ////////Display the add form with posted values within it////
                 $this->data["posted"] = $posted;
             } else {
                 $info = array();
                 $info["s_first_name"] = $posted["s_first_name"];
                 $info["s_last_name"] = $posted["s_last_name"];
                 $info["s_email"] = $posted["s_email"];
                 $info["s_address"] = $posted["s_address"];
                 $info["s_contact_number"] = $posted["s_contact_number"];
                 //print_r($info); exit;
                 //$i_aff=$this->mod_rect->edit_info($info,decrypt($posted["h_id"]));
                 $user_table = $this->db->USER;
                 $arr_where = array('i_id' => decrypt($posted["h_id"]));
                 $i_aff = $this->mod_common->common_edit_info($user_table, $info, $arr_where);
                 if ($i_aff) {
                     set_success_msg($this->cls_msg["save_succ"]);
                     redirect($this->pathtoclass . "account_information/" . $i_id);
                 } else {
                     $this->data["posted"] = $posted;
                     set_error_msg($this->cls_msg["save_err"]);
                 }
                 unset($info, $posted, $i_aff);
             }
         } else {
             $info = $this->user_model->fetch_this(decrypt($i_id));
             $posted = array();
             //$posted["txt_country"]  = trim($info["s_country"]);
             $posted = $info;
             $posted["h_id"] = $i_id;
             $posted["i_id"] = decrypt($i_id);
             $this->data["posted"] = $posted;
             unset($info, $posted);
         }
         ////////////end Submitted Form///////////
         $this->render("my_account/account-edit");
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }
예제 #8
0
 public function remove_information($i_id = 0)
 {
     try {
         echo $i_id;
         exit;
         $i_ret_ = 0;
         $pageno = $this->input->post("h_pageno");
         //the pagination page no, to return at the same page
         //Deleting What?//
         $s_del_these = $this->input->post("h_list");
         switch ($s_del_these) {
             case "all":
                 $i_ret_ = $this->mod_rect->delete_info(-1);
                 break;
             default:
                 //Deleting selected,page //
                 //First consider the posted ids, if found then take $i_id value//
                 $id = !$i_id ? $this->input->post("chk_del") : $i_id;
                 //may be an array of IDs or single id
                 if (is_array($id) && !empty($id)) {
                     //Deleting Information//
                     $tot = count($id) - 1;
                     while ($tot >= 0) {
                         $i_ret_ = $this->mod_rect->delete_info(decrypt($id[$tot]));
                         $tot--;
                     }
                 } elseif ($id > 0) {
                     $i_ret_ = $this->mod_rect->delete_info(decrypt($id));
                 }
                 break;
         }
         unset($s_del_these, $id, $tot);
         if ($i_ret_) {
             set_success_msg($this->cls_msg["delete_succ"]);
         } else {
             set_error_msg($this->cls_msg["delete_err"]);
         }
         redirect($this->pathtoclass . "show_list" . ($pageno ? "/" . $pageno : ""));
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }
예제 #9
0
 public function modify_information($i_id = 0)
 {
     try {
         $this->data['pathtoclass'] = $this->pathtoclass;
         $this->data['mode'] = "edit";
         $this->data['heading'] = addslashes(t("Admin Site Setting"));
         $this->data['BREADCRUMB'] = array('Site Setting');
         ////////////Submitted Form///////////
         if ($_POST) {
             $posted = array();
             $posted["h_id"] = trim($this->input->post("h_id"));
             $posted["txt_admin_email"] = trim($this->input->post("txt_admin_email"));
             $posted["txt_smtp_host"] = trim($this->input->post("txt_smtp_host"));
             $posted["txt_smtp_password"] = trim($this->input->post("txt_smtp_password"));
             $posted["txt_smtp_userid"] = trim($this->input->post("txt_smtp_userid"));
             $posted["i_records_per_page"] = trim($this->input->post("i_records_per_page"));
             $posted["i_project_posting_approval"] = $this->input->post("i_project_posting_approval");
             $posted["i_banner_speed"] = $this->input->post("i_banner_speed");
             $posted["i_featured_slider_speed"] = $this->input->post("i_featured_slider_speed");
             $posted["i_auto_slide_control"] = $this->input->post("i_auto_slide_control");
             $posted["i_featured_project_auto_slide_control"] = $this->input->post("i_featured_project_auto_slide_control");
             $posted["s_facebook_url"] = trim($this->input->post("s_facebook_url"));
             $posted["s_g_plus_url"] = trim($this->input->post("s_g_plus_url"));
             $posted["s_linked_in_url"] = trim($this->input->post("s_linked_in_url"));
             $posted["s_twitter_url"] = trim($this->input->post("s_twitter_url"));
             $posted["s_rss_feed_url"] = trim($this->input->post("s_rss_feed_url"));
             $this->form_validation->set_rules('txt_admin_email', addslashes(t('admin email')), 'trim|required|valid_email');
             $this->form_validation->set_rules('i_records_per_page', addslashes(t('number of records per page')), 'trim|required');
             /*$this->form_validation->set_rules('txt_smtp_host', 'smtp host', 'required');
                           $this->form_validation->set_rules('txt_smtp_password', 'smtp password', 'required');
             		$this->form_validation->set_rules('txt_smtp_userid', 'smtp user id', 'required');*/
             $info = array();
             if ($this->form_validation->run() == FALSE) {
                 $this->data["posted"] = $posted;
             } else {
                 $info["s_admin_email"] = $posted["txt_admin_email"];
                 /*$info["s_smtp_host"]		=   $posted["txt_smtp_host"];
                   $info["s_smtp_password"]	=   $posted["txt_smtp_password"];
                   $info["s_smtp_userid"]	  =   $posted["txt_smtp_userid"];*/
                 $info["i_records_per_page"] = $posted["i_records_per_page"];
                 $info["i_project_posting_approval"] = $posted["i_project_posting_approval"];
                 $info["i_banner_speed"] = $posted["i_banner_speed"];
                 $info["i_featured_slider_speed"] = $posted["i_featured_slider_speed"];
                 $info["i_auto_slide_control"] = $posted["i_auto_slide_control"];
                 $info["i_featured_project_auto_slide_control"] = $posted["i_featured_project_auto_slide_control"];
                 $info["s_facebook_url"] = $posted["s_facebook_url"];
                 $info["s_g_plus_url"] = $posted["s_g_plus_url"];
                 $info["s_linked_in_url"] = $posted["s_linked_in_url"];
                 $info["s_twitter_url"] = $posted["s_twitter_url"];
                 $info["s_rss_feed_url"] = $posted["s_rss_feed_url"];
                 $i_aff = $this->mod_rect->edit_info($info, decrypt($posted['h_id']));
                 if ($i_aff) {
                     set_success_msg($this->cls_msg["save_succ"]);
                     redirect($this->pathtoclass . "modify_information");
                 } else {
                     $this->data["posted"] = $posted;
                     set_error_msg($this->cls_msg["save_err"]);
                 }
                 unset($info, $posted);
             }
         } else {
             $info = $this->mod_rect->fetch_this("NULL");
             // This method id modified by Jagannath Samanta on 24 June 2011
             $posted = array();
             $posted["i_id"] = $info["i_id"];
             $posted["txt_admin_email"] = $info["s_admin_email"];
             $posted["txt_smtp_host"] = $info["s_smtp_host"];
             $posted["txt_smtp_password"] = $info["s_smtp_password"];
             $posted["txt_smtp_userid"] = $info["s_smtp_userid"];
             $posted["i_records_per_page"] = $info["i_records_per_page"];
             $posted["i_project_posting_approval"] = $info["i_project_posting_approval"];
             $posted["i_banner_speed"] = $info["i_banner_speed"];
             $posted["i_featured_slider_speed"] = $info["i_featured_slider_speed"];
             $posted["i_auto_slide_control"] = $info["i_auto_slide_control"];
             $posted["i_featured_project_auto_slide_control"] = $info["i_featured_project_auto_slide_control"];
             $posted["s_facebook_url"] = $info["s_facebook_url"];
             $posted["s_g_plus_url"] = $info["s_g_plus_url"];
             $posted["s_linked_in_url"] = $info["s_linked_in_url"];
             $posted["s_twitter_url"] = $info["s_twitter_url"];
             $posted["s_rss_feed_url"] = $info["s_rss_feed_url"];
             $posted["h_id"] = trim(encrypt($info["i_id"]));
             $this->data["posted"] = $posted;
             unset($info, $posted);
         }
         $this->render('site_setting/site_setting');
         ////Put the select statement here
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }
예제 #10
0
 public function generate()
 {
     if ($_POST) {
         //pr($_POST,1);
         $table_name = $this->input->post('table_name');
         $label = $this->input->post('label');
         $show_in_view_page = $this->input->post('listing');
         $search_field = $this->input->post('searching');
         $form_field_type = $this->input->post('type');
         $validation = $this->input->post('validation');
         $sorting = $this->input->post('sorting');
         // Get table shema
         $table_schema = $this->get_table_schema($table_name);
         $this->get_file_name($table_name);
         $t = array_count_values($show_in_view_page);
         $width_percentage = ceil(100 / intval($t['show']));
         $select_field = '';
         for ($i = 0; $i < count($label); $i++) {
             $field_name = $table_schema[$i + 1]['Field'];
             $select_field[] = 'n.' . $field_name;
             // Generate create/insert section  section for controller fields
             if ($form_field_type[$i] == 'file') {
                 // Generate create/insert section  section for controller fields
                 $file_folder_name = FCPATH . 'uploaded/' . $this->folder_name;
                 if (!file_exists($file_folder_name)) {
                     mkdir($file_folder_name, 0777, true);
                     mkdir($file_folder_name . '/thumb', 0777, true);
                 }
                 $con_c_field .= "\n\n            if(isset(\$_FILES['{$field_name}']) && !empty(\$_FILES['{$field_name}']['name']))\n            {\n                \$s_uploaded = get_file_uploaded(FCPATH.'uploaded/{$this->folder_name}/','{$field_name}','','','{$this->allowedExt}');        \n                \$arr_upload = explode('|',\$s_uploaded);    \n            }\n            if(\$arr_upload[0] == 'ok')\n                \$posted[\"{$field_name}\"] = \$arr_upload[2];\n            ";
             } else {
                 $con_c_field .= "\n\t\t\t\$posted[\"{$field_name}\"] = \$this->input->post(\"{$field_name}\", true);";
             }
             // Generate view field
             $req_symbol = $validation[$i] == 'required' ? '*' : '';
             $class = $i % 2 != 0 ? ' col-md-offset-2' : '';
             if ($i % 2 == 0 && $i > 0) {
                 $vw_c_field .= "\n</div>\n<div class=\"row\">";
             }
             $display = '';
             if ($form_field_type[$i] == 'file') {
                 $display = "\n                    <?php  \n                        if(!empty(\$posted[\"s_image\"]))\n                        {\n                            echo \"<img src='\".base_url('uploaded/" . $this->folder_name . "').'/'.\$posted[\"{$field_name}\"].\"'  style='max-width:100px;max-height:100px;border:none;'/><br><br>\";\n                            echo \"<input type='hidden' name='h_{$field_name}' value='\".\$posted[\"{$field_name}\"].\"' />\";\n                        }\n                    ?>";
             }
             // Check for reference field
             if ($this->input->post("ref_field_{$i}") != '') {
                 $ref_table = $this->input->post("ref_table_{$i}");
                 // Ref table
                 $ref_field = $this->input->post("ref_field_{$i}");
                 // Ref Field
                 $ref_tb_prefix = substr(str_replace($this->tbl_prefix, '', $ref_table), 0, 3);
                 // Ref table prefix
                 $this->ref_tb_list[] = array('table_name' => $ref_table, 'field' => $ref_field, 'prefix' => $ref_tb_prefix, 'main_tb_field' => $field_name);
                 // Generate a method for drop down
                 $con_dd_method = "\n\n\n    // Generate a method for drop down\n    protected function generate_drodown(\$table, \$field, \$s_id = '', \$return_type = 'html')\n    {\n        \$tmp = \$this->acs_model->fetch_data(\$table, '',\"i_id, \$field\");\n        if(!empty(\$tmp))\n        {\n            if(\$return_type == 'array')\n                \$value[0] = 'Select';\n            else\n                \$value = '<option value=\"\">Select</option>';\n            foreach(\$tmp as \$v)\n            {\n                if(\$return_type == 'array')\n                    \$value[\$v['i_id']] = \$v[\$field];\n                else\n                {\n                    \$selected = \$s_id == \$v['i_id'] ? 'selected' : '';\n                    \$value .= '<option value=\"'.\$v['i_id'].'\" '.\$selected.'>'.\$v[\$field].'</option>';\n                }\n            }\n        }\n        unset(\$tmp, \$table, \$field, \$s_id, \$return_type);\n        return \$value;\n    }";
                 // Generate drop down field
                 $tmp = $this->acs_model->fetch_data($ref_table, '', "i_id, {$ref_field}");
                 if (!empty($tmp)) {
                     foreach ($tmp as $v) {
                         $value .= "<option value=\"{$v['i_id']}\">{$v[$ref_field]}</option>";
                     }
                 }
                 unset($tmp);
             }
             if ($value != '') {
                 $form_field_type[$i] = 'select';
             }
             if ($ref_field != '' && $form_field_type[$i] == 'select') {
             }
             $vw_c_field .= "\n\t" . $this->generate_form_field($form_field_type[$i], $label[$i], $field_name, $class, $req_symbol, $value);
             // Generate sorting fields
             if ($sorting[$i] == 'show') {
                 if ($ref_field != '') {
                     $sorting_field[] = "'{$i}'=>'{$ref_tb_prefix}.{$ref_field}'";
                 } else {
                     $sorting_field[] = "'{$i}'=>'n.{$field_name}'";
                 }
             }
             // Generate display view
             $vw_details_field .= "\n\t\t\t<label class=\"col-md-4\"><?php echo addslashes(t('{$field_name}'));?> : </label>\n\t\t\t<div class=\"col-md-8\"><p><?php echo \$info[0]['{$field_name}']; ?></p></div>\n\t\t\t<div class=\"clearfix\"></div>";
             // Generate the form validation rule
             if ($validation[$i] != '') {
                 $con_form_validation .= "\n\t\t\t\$this->form_validation->set_rules('{$field_name}', addslashes(t('" . strtolower($label[$i]) . "')), '{$validation[$i]}|xss_clean');";
                 if ($validation[$i] == 'required') {
                     $vw_form_validation .= "\n\t\tif(\$(\"#{$field_name}\").val()=='')\n\t\t{\n\t\t\tmarkAsError(\$(\"#{$field_name}\"),'<?php echo addslashes(t(\"Please provide " . strtolower($label[$i]) . "\"))?>');\n\t\t\tb_valid = false;\n\t\t}";
                 } else {
                     if ($validation[$i] == 'valid_email') {
                         $vw_form_validation .= "\n\t\tif(reg.test(\$.trim(\$(\"\\#{$field_name}\").val()))== false)\n\t\t{\n\t\t\tmarkAsError(\$(\"#{$field_name}\"),'<?php echo addslashes(t(\"Please provide valid " . strtolower($label[$i]) . "\"))?>');\n\t\t\tb_valid = false;\n\t\t}";
                     }
                 }
             }
             // Generate search field
             if ($search_field[$i] == 'show') {
                 $con_search_field .= "\n\t\t\t\$search_variable[\"{$field_name}\"] = (\$this->input->post(\"h_search\")?\$this->input->post(\"{$field_name}\"):\$arr_session_data[\"{$field_name}\"]);";
                 if ($ref_field != '' && $ref_table != '') {
                     $con_search_inner_field .= "\n\t\t\t\tif(intval(\$search_variable[\"{$field_name}\"])>0)\n\t\t\t\t{\n\t\t\t\t\t\$s_where .= \" AND {$ref_tb_prefix}.i_id = '\".addslashes(\$search_variable[\"{$field_name}\"]).\"' \";\n\t\t\t\t}\n\t\t\t\t\$arr_session[\"{$field_name}\"] = \$search_variable[\"{$field_name}\"];\n\t\t\t\t\$this->data[\"{$field_name}\"] = \$search_variable[\"{$field_name}\"];";
                     $vw_search_field .= "\t\t\t\t\t\t\t\t<div class=\"form-group\">\n\t\t\t\t\t\t\t\t\t<label class=\"\"><?php echo addslashes(t(\"" . $this->get_field_label($ref_field) . "\"))?></label>\n\t\t\t\t\t\t\t\t\t<?php echo form_dropdown('{$field_name}', \$dd_val, (\${$field_name} != ''? array(\${$field_name}) : ''), 'class=\"form-control\"')?>\n\t\t\t\t\t\t\t\t</div>";
                     $con_search_additional .= "\n\t\t\t\t\$this->data['dd_val'] = \$this->generate_drodown('{$ref_table}', '{$ref_field}', \$search_variable[\"{$field_name}\"], 'array');\n";
                 } else {
                     $con_search_inner_field .= "\n\t\t\t\tif(\$search_variable[\"{$field_name}\"]!=\"\")\n\t\t\t\t{\n\t\t\t\t\t\$s_where .= \" AND n.{$field_name} LIKE '%\".addslashes(\$search_variable[\"{$field_name}\"]).\"%' \";\n\t\t\t\t}\n\t\t\t\t\$arr_session[\"{$field_name}\"] = \$search_variable[\"{$field_name}\"];\n\t\t\t\t\$this->data[\"{$field_name}\"] = \$search_variable[\"{$field_name}\"];";
                     $vw_search_field .= "\t\t\t\t\t\t\t\t<div class=\"form-group\">\n\t\t\t\t\t\t\t\t\t<label class=\"\"><?php echo addslashes(t(\"{$label[$i]}\"))?></label>\n\t\t\t\t\t\t\t\t\t<input type=\"text\" name=\"{$field_name}\" id=\"{$field_name}\" value=\"<?php echo \${$field_name}?>\" class=\"form-control\" />\n\t\t\t\t\t\t\t\t</div>";
                 }
             }
             // Generate show list view
             if ($show_in_view_page[$i] == 'show') {
                 $con_show_list_header .= "\n\t\t\t\$table_view[\"headers\"][++\$j][\"width\"] = \"{$width_percentage}%\";\n\t\t\t\$table_view[\"headers\"][\$j][\"align\"] = \"left\";\n\t\t\t\$table_view[\"headers\"][\$j][\"val\"] = addslashes(t(\"{$label[$i]}\"));";
                 if ($sorting[$i] == 'show') {
                     $con_show_list_header .= "\n\t\t\t\$table_view[\"headers\"][\$j][\"sort\"] = array('field_name'=>encrypt(\$arr_sort[{$i}]));";
                 }
                 if ($form_field_type[$i] == 'image_upload') {
                     $con_show_list_view .= "\n\t\t\t\t\$table_view[\"tablerows\"][\$i][\$i_col++] = \"<img src='\".base_url('uploaded/{$this->folder_name}').\"/\".\$info[\$i][\"{$field_name}\"].\"' style='max-width:80px; max-height:80px;' alt='{$this->field_label}'/>\";";
                 } else {
                     if ($ref_field != '') {
                         $field_name = $ref_field;
                     }
                     $con_show_list_view .= "\n\t\t\t\t\$table_view[\"tablerows\"][\$i][\$i_col++] = \$info[\$i][\"{$field_name}\"];";
                 }
             }
             unset($field_name, $class, $req_symbol, $value, $ref_table, $ref_field, $ref_tb_prefix);
         }
         // End of main loop
         // Write on file
         ##--------------------------------------------------------------------------------------##
         ##  Write script to the controller                                                      ##
         ##--------------------------------------------------------------------------------------##
         // Generate the controller file (Path to controller)
         $this->controller_file = FCPATH . 'application/controllers/' . $this->admin_folder_name . $this->file_name . '.php';
         $controller = "<?php \n\n/***\n";
         $controller .= $this->generate_file_info($this->file_name . '.php');
         $controller .= "class " . ucfirst($this->file_name) . " extends MY_Controller \n{";
         // Add class name
         $controller .= $this->generate_contruct($table_name);
         $tbl = '';
         if (!empty($this->ref_tb_list)) {
             $tbl .= "\n\n            \$tbl[0] = array(\n                'tbl' => \$this->tbl.' AS n',\n                'on' =>''\n            );";
             for ($i = 0; $i < count($this->ref_tb_list); $i++) {
                 $select_field[] = $this->ref_tb_list[$i]['prefix'] . '.' . $this->ref_tb_list[$i]['field'];
                 $tbl .= "\n\n            \$tbl[" . ($i + 1) . "] = array(\n                'tbl' => \$this->tbl_ref_{$this->ref_tb_list[$i]['prefix']}.' AS {$this->ref_tb_list[$i]['prefix']}',\n                'on' => 'n.{$this->ref_tb_list[$i]['main_tb_field']} = {$this->ref_tb_list[$i]['prefix']}.i_id'\n            );";
             }
         }
         $select_field = count($select_field) > 0 ? 'n.i_id, ' . implode(', ', $select_field) : 'n.*';
         // Generate show_list method
         $controller .= "\n\n    /****\n    * Display the list of records \n    */\n    public function show_list(\$order_by = '{$default_sort}', \$sort_type = 'desc',\$start = NULL, \$limit = NULL)\n    {\n        try\n        {\n            \$this->data['heading'] = addslashes(t(\"{$this->mvc_title}\")); //Package Name[@package] Panel Heading\n            \n            //generating search query//\n            \$arr_session_data = \$this->session->userdata(\"arr_session\");\n            if(\$arr_session_data['searching_name'] != \$this->data['heading'])\n            {\n                \$this->session->unset_userdata(\"arr_session\");\n                \$arr_session_data = array();\n            }\n            \n            \$search_variable = array();\n            //Getting Posted or session values for search//        \n            \$s_search = (isset(\$_POST[\"h_search\"])?\$this->input->post(\"h_search\"):\$this->session->userdata(\"h_search\"));{$con_search_field}\n            //end Getting Posted or session values for search//            \n            \n            \$s_where = \" n.i_id != 0 \";\n            if(\$s_search == \"advanced\")\n            {\n                \$arr_session = array();\n                \$arr_session[\"searching_name\"] = \$this->data['heading'];\n                {$con_search_inner_field}\n                \$this->session->set_userdata(\"arr_session\",\$arr_session);\n                \$this->session->set_userdata(\"h_search\",\$s_search);\n                \$this->data[\"h_search\"] = \$s_search;                            \n            }\n            else //List all records, **not done\n            {\n                //Releasing search values from session//\n                \$this->session->unset_userdata(\"arr_session\");\n                \$this->session->unset_userdata(\"h_search\");\n                \n                \$this->data[\"h_search\"] = \$s_search;\n                \$this->data[\"{$search_field}\"] = ''; \n                //end Storing search values into session//                 \n            }\n            {$con_search_additional}\n            unset(\$s_search,\$arr_session,\$search_variable);\n              \n            //Setting Limits, If searched then start from 0//\n            \$i_uri_seg = 6;\n            \$start = \$this->input->post(\"h_search\") ? 0 : \$this->uri->segment(\$i_uri_seg);\n            //end generating search query//\n            \n            // List of fields for sorting\n            \$arr_sort = array(" . implode(', ', $sorting_field) . ");   \n            \$order_by = !empty(\$order_by)?in_array(decrypt(\$order_by),\$arr_sort)?decrypt(\$order_by):\$arr_sort[0]:\$arr_sort[0];\n            \n            \$limit = \$this->i_admin_page_limit;";
         if ($tbl != '') {
             $controller .= "\n\t\t\t{$tbl}\n            \$conf = array(\n                'select' => '{$select_field}',\n                'where' => \$s_where,\n                'limit' => \$limit,\n                'offset' => \$start,\n                'order_by' => \$order_by,\n                'order_type' => \$sort_type\n            );\n            \$info = \$this->acs_model->fetch_data_join(\$tbl, \$conf);\n            \n            \$conf2 = array(\n                'select' => 'count(n.i_id) AS total',\n                'where' => \$s_where\n            );\n            \$tmp =  \$this->acs_model->fetch_data_join(\$tbl, \$conf2);\n            \$total = \$tmp[0]['total'];\n            unset(\$tmp);\n";
         } else {
             $controller .= "\n\n            \$s_where .= \" ORDER BY \$order_by \$sort_type\"; \n            \$info = \$this->acs_model->fetch_data(\$this->tbl.' AS n', \$s_where, '', intval(\$start), \$limit);\n            \$total = \$this->acs_model->count_info(\$this->tbl.' AS n', \$s_where, 'n.');";
         }
         $controller .= "\n                  \n            //Creating List view for displaying//\n            \$table_view = array();  \n            \n            //Table Headers, with width,alignment//\n            \$table_view[\"caption\"]                 = addslashes(t(\"{$this->mvc_title}\"));\n            \$table_view[\"total_rows\"]              = count(\$info);\n            \$table_view[\"total_db_records\"]        = \$total;\n            \$table_view[\"detail_view\"]             = false;  // to disable show details. \n            \$table_view[\"order_name\"]              = encrypt(\$order_by);\n            \$table_view[\"order_by\"]                = \$sort_type;\n            \$table_view[\"src_action\"]              = \$this->pathtoclass.\$this->router->fetch_method();\n            \n            \$j = -1;\n            {$con_show_list_header}\n            //end Table Headers, with width,alignment//\n            \n            //Table Data//\n            for(\$i = 0; \$i< \$table_view[\"total_rows\"]; \$i++)\n            {\n                \$i_col = 0;\n                \$table_view[\"tablerows\"][\$i][\$i_col++] = encrypt(\$info[\$i][\"i_id\"]);                \n                {$con_show_list_view}\n            } \n            //end Table Data//\n            unset(\$i, \$i_col, \$start, \$limit, \$s_where); \n            \n            //\$this->data[\"table_view\"] = \$this->admin_showin_table(\$table_view,TRUE);\n            \$this->data['total_record'] = \$table_view[\"total_db_records\"];\n            \$this->data[\"table_view\"] = \$this->admin_showin_order_table(\$table_view,TRUE);\n            \n            //Creating List view for displaying//\n            \$this->data[\"search_action\"] = \$this->pathtoclass.\$this->router->fetch_method();//used for search form action\n            \n            \$this->render();          \n            unset(\$table_view, \$info);\n        }\n        catch(Exception \$err_obj)\n        {\n            show_error(\$err_obj->getMessage());\n        }          \n    }\n";
         // Generate add_information method
         $controller .= "\n \n    /***\n    * Method to Display and Save New information\n    * This have to sections: \n    *  >>Displaying Blank Form for new entry.\n    *  >>Saving the new information into DB\n    * After Posting the form, the posted values must be\n    * shown in the form if any error occurs to avoid re-entry of the form.\n    * \n    * On Success redirect to the showList interface else display error here.\n    */\n    public function add_information()\n    {\n        \$this->data['heading'] = (t(\"Add Information\"));\n        \$this->data['pathtoclass'] = \$this->pathtoclass;\n        \$this->data['BREADCRUMB'] = array(addslashes(t('Add Information')));\n        \$this->data['mode'] = 'add';\n        {$con_search_additional}\n        \n        if(\$_POST)\n        {\n            \$posted = array();\n            " . $con_c_field . " ";
         if ($con_form_validation != '') {
             $controller .= $con_form_validation;
             $controller .= "\n            if(\$this->form_validation->run() == FALSE /*|| \$arr_upload[0]==='err'*/)//invalid\n            {\n                /*if(\$arr_upload[0]==='err')\n                    set_error_msg(\$arr_upload[2]);\n                else\n                    get_file_deleted(\$this->uploaddir,\$arr_upload[2]);\n                */\n                //Display the add form with posted values within it//\n                \$this->data[\"posted\"] = \$posted;\n            }\n            else//validated, now save into DB\n            {\n                ";
         }
         $controller .= "\n                \$i_newid = \$this->acs_model->add_data(\$this->tbl, \$posted);\n                if(\$i_newid)//saved successfully\n                {\n                    /*\n                    if(\$arr_upload[0]==='ok')\n                    {\n                        get_image_thumb(\$this->uploaddir.\$posted[\"s_image\"], \$this->thumbdir, 'thumb_'.\$posted[\"s_image\"],\$this->thumbHt,\$this->thumbWd);\n                    }\n                    */\n                    set_success_msg(\$this->cls_msg[\"save_succ\"]);\n                    redirect(\$this->pathtoclass.\"show_list\");\n                }\n                else//Not saved, show the form again\n                {\n                    set_error_msg(\$this->cls_msg[\"save_err\"]);\n                }";
         if ($con_form_validation != '') {
             $controller .= "\n\t\t\t}";
         }
         $controller .= "\n        }\n        //end Submitted Form//\n        \n        \$this->render(\"{$this->folder_name}/add-edit\");\n    }";
         // Generate modify_information method
         $controller .= "\n\n    /***\n    * Method to Display and Save Updated information\n    * This have to sections: \n    *  >>Displaying Values in Form for modifying entry.\n    *  >>Saving the new information into DB    \n    * After Posting the form, the posted values must be\n    * shown in the form if any error occurs to avoid re-entry of the form.\n    * \n    * On Success redirect to the showList interface else display error here. \n    * @param int \$i_id, id of the record to be modified.\n    */\n    public function modify_information(\$i_id=0)\n    {\n        \$this->data['heading'] = (t(\"Edit Information\"));\n        \$this->data['pathtoclass'] = \$this->pathtoclass;\n        \$this->data['BREADCRUMB'] = array(addslashes(t('Edit Information')));\n        \$this->data['mode'] = 'edit';\n        {$con_search_additional}\n        \n        if(\$_POST)\n        {\n            \$posted = array();\n        " . $con_c_field;
         $controller .= "\n\n            \$posted[\"h_id\"] = \$this->input->post(\"h_id\", true);";
         if ($con_form_validation != '') {
             $controller .= $con_form_validation;
             $controller .= "\n            if(\$this->form_validation->run() == FALSE /*|| \$arr_upload[0]==='err'*/)//invalid\n            {\n                /*if(\$arr_upload[0]==='err')\n                    set_error_msg(\$arr_upload[2]);\n                else\n                    get_file_deleted(\$this->uploaddir,\$arr_upload[2]);\n                */\n                //Display the add form with posted values within it//\n                \$this->data[\"posted\"] = \$posted;\n            }\n            else//validated, now save into DB\n            {\n                ";
         }
         $controller .= "\n                \$i_id = decrypt(\$posted[\"h_id\"]);\n                unset(\$posted[\"h_id\"]);\n                \$i_aff = \$this->acs_model->edit_data(\$this->tbl,\$posted, array('i_id'=>\$i_id));\n                if(\$i_aff)//saved successfully\n                {\n                    /*\n                    if(\$arr_upload[0]==='ok')\n                    {\n                        get_image_thumb(\$this->uploaddir.\$posted[\"s_image\"], \$this->thumbdir, 'thumb_'.\$posted[\"s_image\"],\$this->thumbHt,\$this->thumbWd);\n                    }\n                    */\n                    set_success_msg(\$this->cls_msg[\"save_succ\"]);\n                    redirect(\$this->pathtoclass.\"show_list\");\n                }\n                else//Not saved, show the form again\n                {\n                    set_error_msg(\$this->cls_msg[\"save_err\"]);\n                }";
         if ($con_form_validation != '') {
             $controller .= "\n\t\t\t}";
         }
         $controller .= "\n        }//end Submitted Form//\n        else\n        {\n            // Fetch all the data\n            \$tmp = \$this->acs_model->fetch_data(\$this->tbl,array('i_id'=>decrypt(\$i_id)));\n            \$posted = \$tmp[0];\n            \$posted['h_id'] = \$i_id;\n            \$this->data['posted'] = \$posted;\n            \$posted['h_mode'] = \$this->data['mode'];\n        }\n        \n        \$this->render(\"{$this->folder_name}/add-edit\");\n    }";
         // Generate view_detail method
         $controller .= "\n\n    /***\n    * Shows details of a single record.\n    * \n    * @param int \$i_id, Primary key\n    */\n    public function view_detail(\$i_id = 0)\n    {\n        try\n        {\n            if(!empty(\$i_id))\n            {\n                \$this->data[\"info\"] = \$this->acs_model->fetch_data(\$this->tbl,array('i_id'=>\$i_id));\n            }\n            \$this->load->view('{$this->admin_folder_name}{$this->folder_name}/show_detail.tpl.php', \$this->data); \n        }\n        catch(Exception \$err_obj)\n        {\n            show_error(\$err_obj->getMessage());\n        }         \n    }";
         // Generate ajax_remove_information method
         $controller .= "\n\n    /***\n    * Method to Delete information\n    * This have no interface but db operation \n    * will be done here.\n    * \n    * On Success redirect to the showList interface else display error in showList interface. \n    * @param int \$i_id, id of the record to be modified.\n    */  \n    public function ajax_remove_information()\n    {\n        try\n        {\n            \$i_id = decrypt(\$this->input->post(\"temp_id\"));\n            echo \$this->acs_model->delete_data(\$this->tbl, array('i_id'=>\$i_id)) ? 'ok' : 'error';\n            unset(\$i_id);\n        }\n        catch(Exception \$err_obj)\n        {\n            show_error(\$err_obj->getMessage());\n        }         \n    }";
         if ($con_dd_method != '') {
             $controller .= "\n\t" . $con_dd_method;
         }
         $controller .= $this->generate_destruct();
         $controller .= "\n}";
         file_put_contents($this->controller_file, $controller);
         ##--------------------------------------------------------------------------------------##
         ##  End COntroller section                                                              ##
         ##--------------------------------------------------------------------------------------##
         ##--------------------------------------------------------------------------------------##
         ##  Write script to the view                                                            ##
         ##--------------------------------------------------------------------------------------##
         mkdir(FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name);
         // Generate the view file for show_list.tpl.php  (Path to view)
         $this->show_list_view_file = FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name . '/show_list.tpl.php';
         $show_list_view = "<?php \n\n/***\n";
         $show_list_view .= $this->generate_file_info($this->file_name . " show_list.tpl.php") . "\n?>";
         $show_list_view .= "\n<script>var g_controller=\"<?php echo \$pathtoclass;?>\", search_action = '<?php echo \$search_action;?>';// Controller Path </script>";
         $show_list_view .= "\n<script src=\"<?php echo base_url()?>resource/admin/js/custom_js/add_edit_view.js\" type=\"text/javascript\"></script>";
         $show_list_view .= "\n\n<div class=\"container-fluid\">\n    <div class=\"row\">\n        <div class=\"col-md-10 col-md-offset-1\">\n            <div class=\"row\">\n                <div class=\"col-md-8 col-md-offset-2\">\n        \n                    <div class=\"box-header well\">\n                        <h2><?php echo addslashes(t(\"Search\"))?></h2>             \n                    </div>\n    \n                    <?php show_all_messages(); ?>\n                    <form class=\"form-horizontal\" id=\"frm_search_3\" name=\"frm_search_3\" method=\"post\" action=\"<?php echo \$search_action?>\" >\n                        <input type=\"hidden\" id=\"h_search\" name=\"h_search\" value=\"\" />    \n                    </form>\n            \n                    <form class=\"\" id=\"frm_search_2\" name=\"frm_search_2\" method=\"post\" action=\"\" >\n                        <input type=\"hidden\" id=\"h_search\" name=\"h_search\" value=\"advanced\" />        \n                        <div id=\"div_err_2\"></div>        \n                        <div class=\"row\">\n                            <div class=\"col-md-5\">\n                            {$vw_search_field}\n                            </div>\n                        </div>\n                        <div class=\"form-group\">\n                            <button type=\"button\" search=\"2\" id=\"btn_submit\" name=\"btn_submit\" class=\"btn btn-primary\"><?php echo addslashes(t(\"Search\"))?></button>                 \n                            <button type=\"button\" id=\"btn_srchall\" name=\"btn_srchall\" class=\"btn\"><?php echo addslashes(t(\"Show All\"))?></button>\n                        </div>\n                    </form>  \n                </div>\n            </div>\n\n            <?php echo \$table_view;?><!-- content ends -->\n        </div>\n    </div>\n</div>\n";
         file_put_contents($this->show_list_view_file, $show_list_view);
         // Write add-edit.tpl.php
         // Generate the view file for add-edit.tpl.php  (Path to view)
         $this->view_file = FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name . '/add-edit.tpl.php';
         $view = "<?php \n\n/***\n";
         $view .= $this->generate_file_info($this->file_name . " add-edit.tpl.php") . "\n?>";
         $view .= "\n<script>var g_controller=\"<?php echo \$pathtoclass;?>\", search_action = '<?php echo \$search_action;?>';// Controller Path </script>";
         $view .= "\n<script src=\"<?php echo base_url()?>resource/admin/js/custom_js/add_edit_view.js\" type=\"text/javascript\"></script>";
         // Generate the javascript form validation
         if ($vw_form_validation != '') {
             /*$view_javascript_file = FCPATH.'resource/admin/js/custom_js/'.$this->file_name.'.js';
               $view .= "\n<script src=\"<?php echo base_url()?>resource/admin/js/custom_js/{$this->file_name}.js\" type=\"text/javascript\"></script>\n";*/
             $view .= "\n<script type\"text/javascript\">\n\$(document).ready(function(){\n    //Submitting the form//\n    \$(\"#frm_add_edit\").submit(function(){\n        var b_valid=true;\n        var s_err='';\n        var email_pattern = /^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})\$/;\n        \$(\"#div_err\").hide(\"slow\");\n        {$vw_form_validation}\n        //validating//\n        if(!b_valid)\n        {        \n            \$(\"#div_err\").html('<div id=\"err_msg\" class=\"error_massage\">'+s_err+'</div>').show(\"slow\");\n        }\n    \n        return b_valid;\n    });\n});\n</script>";
             //file_put_contents($view_javascript_file, $js);
         }
         $view .= "\n<div class=\"container-fluid\">\n    <div class=\"row\">\n        <div class=\"col-md-10 col-md-offset-1\">\n            <div class=\"box-header\">\n                <h3 class=\"box-title\"><?php echo \$heading;?></h3>\n            </div><!-- /.box-header -->\n            \n            <!-- form start -->\n            <?php show_all_messages();?>\n            <form role=\"form\" id=\"frm_add_edit\" name=\"frm_add_edit\" action=\"\" method=\"post\" autocomplete=\"off\"  enctype=\"multipart/form-data\">\n                <input type=\"hidden\" id=\"h_id\" name=\"h_id\" value=\"<?php echo \$posted[\"h_id\"];?>\">\n                <div class=\"row\">\n                " . $vw_c_field . "\n                </div>\n                \n                <div class=\"form-group\">\n                    <input type=\"button\" id=\"btn_save\" name=\"btn_save\" class=\"btn btn-primary\" value=\"<?php echo addslashes(t(\"Save changes\"))?>\">\n                    <input type=\"button\" id=\"btn_cancel\" name=\"btn_cancel\" class=\"btn\" value=\"<?php echo addslashes(t(\"Cancel\"))?>\">\n                </div>\n            </form>\n        </div>\n    </div><!--/row-->\n</div><!-- content ends -->\n";
         file_put_contents($this->view_file, $view);
         // Write add-edit.tpl.php
         // Generate view for view_detail.tpl.php
         $view_detail_view_file = FCPATH . 'application/views/' . $this->admin_folder_name . $this->folder_name . '/view_detail.tpl.php';
         $view_detail_view = "<?php \n\n/***\n";
         $view_detail_view .= $this->generate_file_info($this->file_name . " view_detail.tpl.php") . "\n?>";
         $view_detail_view .= "\n\n<div id=\"content\" class=\"\" style=\"max-height:500px; width:700px;overflow-x:hidden; overflow-y:scroll;\">\n   <div class=\"container-fluid\">\n      <h2><?php echo addslashes(t('View Detail'))?></h2>    \n              \n      <div class=\"row\">\n      {$vw_details_field}\n      </div>\n   </div>\n</div>\n";
         file_put_contents($view_detail_view_file, $view_detail_view);
         // Write view_detail.tpl.php file
         ##--------------------------------------------------------------------------------------##
         ##  End View Section                                                                    ##
         ##--------------------------------------------------------------------------------------##
         set_success_msg('CRUD has been generated successfully');
         // Add this to menu and menu_permit table
         $prev = $this->db->select('i_id', false)->get_where($this->tbl_prefix . 'menu', array('s_link' => $this->file_name . '/'))->num_rows();
         if ($prev == 0) {
             $this->db->insert($this->tbl_prefix . 'menu', array('s_name' => $this->mvc_title, 's_link' => $this->file_name . '/', 'i_parent_id' => 1, 'i_main_id' => 1, 's_action_permit' => 'View List||View Detail||Add||Edit||Delete', 'en_s_name' => $this->mvc_title));
             $insert_id = $this->db->insert_id();
             if ($insert_id > 0) {
                 $info = array(array('i_menu_id' => $insert_id, 's_action' => 'View List', 's_link' => $this->file_name . '/show_list/'), array('i_menu_id' => $insert_id, 's_action' => 'View Detail', 's_link' => $this->file_name . '/view_detail/'), array('i_menu_id' => $insert_id, 's_action' => 'Add', 's_link' => $this->file_name . '/add_information/'), array('i_menu_id' => $insert_id, 's_action' => 'Edit', 's_link' => $this->file_name . '/modify_information/'), array('i_menu_id' => $insert_id, 's_action' => 'Delete', 's_link' => $this->file_name . '/delete_information/'));
                 $this->db->insert_batch($this->tbl_prefix . 'menu_permit', $info);
             }
         }
         unset($con_form_validation, $vw_form_validation, $con_dd_method, $this->ref_tb_list, $sorting, $sorting_field);
     }
     redirect($this->pathtoclass);
 }
예제 #11
0
 public function ajax_remove_information()
 {
     try {
         $i_id = decrypt($this->input->post("temp_id"));
         $i_rect = $this->mod_rect->delete_info($i_id);
         /*don't change*/
         if ($i_rect) {
             set_success_msg($this->cls_msg['delete_succ']);
             echo "ok";
         } else {
             set_error_msg($this->cls_msg['delete_err']);
             echo "error";
         }
         unset($info, $i_rect);
     } catch (Exception $err_obj) {
         show_error($err_obj->getMessage());
     }
 }