Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.52 KB | None | 0 0
  1. class Home extends CI_Model{
  2.  
  3. //SQL
  4.  
  5. function get_prodTYPE(){
  6. $this->db->select()->from('producttype')->where('active',1);
  7. $query=$this->db->get();
  8. return $query->result_array();
  9. }
  10.  
  11. function get_COUNTRY(){
  12. $this->db->select()->from('pais');
  13. $this->db->order_by("id_pais", "asc");
  14. $result = $this->db->get('pais');
  15. $resultado = array();
  16. if($result->num_rows() > 0){
  17. $resultado[''] = 'please select';
  18. foreach($result->result_array() as $row){
  19. $resultado[$row['id_pais']] = $row['Pais'];
  20. }
  21. }
  22. return $resultado;
  23. }
  24.  
  25. function register(){
  26.  
  27. if(!$this->session->userdata('userID')){
  28.  
  29. $data['prodTYPE']=$this->home->get_prodTYPE();
  30. $data['info']=$this->home->get_info();
  31. $data['country']=$this->home->get_COUNTRY();
  32.  
  33.  
  34. //validacao
  35. $config=array(
  36.  
  37. array(
  38. 'field'=>'username',
  39. 'label'=>'Username',
  40. 'rules'=>'trim|required|is_unique[users.username]|callback_min_lenght_3'
  41. ),
  42.  
  43. array(
  44. 'field'=>'password',
  45. 'label'=>'Password',
  46. 'rules'=>'trim|required|callback_min_lenght_6'
  47. ),
  48.  
  49. array(
  50. 'field'=>'password2',
  51. 'label'=>'Password de Confirmação',
  52. 'rules'=>'trim|required|matches[password]'
  53. ),
  54.  
  55. array(
  56. 'field'=>'email',
  57. 'label'=>'Email',
  58. 'rules'=>'trim|required|is_unique[users.email]|valid_email'
  59. ),
  60.  
  61. array(
  62. 'field'=>'name',
  63. 'label'=>'Nome',
  64. 'rules'=>'trim|required|callback_username_check|callback_min_lenght_3'
  65. ),
  66.  
  67. array(
  68. 'field'=>'contact',
  69. 'label'=>'Contacto',
  70. 'rules'=>'trim|required|numeric|callback_min_lenght_9'
  71. ),
  72.  
  73. array(
  74. 'field'=>'address',
  75. 'label'=>'Morada',
  76. 'rules'=>'trim|required|callback_adress_check|callback_min_lenght_9'
  77. ),
  78.  
  79. array(
  80. 'field'=>'postalCODE',
  81. 'label'=>'Codigo Postal',
  82. 'rules'=>'trim|required|numeric]|callback_min_lenght_4'
  83. ),
  84.  
  85. array(
  86. 'field'=>'postalCODE2',
  87. 'label'=>'Codigo Postal',
  88. 'rules'=>'trim|required|numeric|callback_min_lenght_3'
  89. ),
  90.  
  91. array(
  92. 'field'=>'city',
  93. 'label'=>'Localidade',
  94. 'rules'=>'trim|required|callback_min_lenght_3|callback_city_check'
  95. ),
  96.  
  97. array(
  98. 'field'=>'taxpayerNUMBER',
  99. 'label'=>'N.º Contribuinte',
  100. 'rules'=>'trim|required|numeric|callback_min_lenght_9'
  101. ),
  102.  
  103. );
  104.  
  105. $this->form_validation->set_rules($config);
  106.  
  107. if($this->form_validation->run() == FALSE){//erro
  108. $data['errors']=validation_errors();
  109.  
  110. } else {//registo
  111. $data=array(
  112. 'username'=>$_POST['username'],
  113. 'userTYPE'=>'user',
  114. 'password'=>sha1($_POST['password']),
  115. 'email'=>$_POST['email'],
  116. 'active'=>$_POST['newsletter']==null?0:1,
  117. 'name'=>$_POST['name'],
  118. 'contact'=>$_POST['contact'],
  119. 'country'=>$_POST['country'],
  120. 'address'=>$_POST['address'],
  121. 'postalCODE'=>$_POST['postalCODE'],
  122. 'postalCODE2'=>$_POST['postalCODE2'],
  123. 'city'=>$_POST['city'],
  124. 'taxpayerNUMBER'=>$_POST['taxpayerNUMBER']
  125. );
  126. $userid = $this->user->create_user($data);
  127.  
  128. $data_init=array(
  129. 'userID'=>$userid['userID'],
  130. 'situation'=>0
  131. );
  132.  
  133. $this->user->init_shop($data_init);//comecar encomendas
  134.  
  135. $this->session->set_userdata('userID',$userid['userID']);
  136. $this->session->set_userdata('userTYPE',$userid['userTYPE']);//userTYPE
  137. $this->session->set_userdata('userNAME',$userid['username']);
  138. $this->session->set_userdata('newsletter',$_POST['newsletter']==null?0:1);
  139.  
  140.  
  141. redirect(base_url().'/index.php/emails/email_to/'.$userid['userID']);
  142. }
  143. $data['page']="#fragment-3";
  144. $this->load->view('header',$data);
  145. $this->load->view('login',$data);
  146. $this->load->view('footer');
  147. } else {
  148. redirect(base_url().'/index.php/');
  149. }
  150. }
  151.  
  152. <div id="fragment-3">
  153.  
  154. <?php echo form_open(base_url().'index.php/users/register'); ?>
  155. <div id="user_r"><?=form_label('Username','username')?><?php
  156. $data_form=array(
  157. 'id'=>'username',
  158. 'name'=>'username',
  159. 'size'=>50,
  160. 'maxlength'=>'20',
  161. 'placeholder'=>'username',
  162. );
  163. ?></div><div id="user_r_b"><?php echo form_input($data_form)?></div>
  164.  
  165.  
  166. <div id="mail_r"><?=form_label('Email','email')?><?php
  167. $data_form=array(
  168. 'id'=>'email',
  169. 'name'=>'email',
  170. 'size'=>50,
  171. 'maxlength'=>'40',
  172. 'placeholder'=>'email válido',
  173. );
  174. ?></div><div id="mail_r_b"><?php echo form_input($data_form)?></div>
  175.  
  176.  
  177. <div id="news_u"><?=form_label('Newsletter','newsletter')?><?php
  178. $data_form=array(
  179. 'name'=>'newsletter',
  180. 'id'=>'newsletter',
  181. 'checked'=>TRUE,
  182. 'value'=>1,
  183. 'style'=>'margin:10px',
  184. );
  185. ?></div>
  186. <div id="news_u_b"><?php echo form_checkbox($data_form)?></div>
  187.  
  188.  
  189. <div id="pass_1"><?=form_label('Password','password')?><?php
  190. $data_form=array(
  191. 'name'=>'password',
  192. 'id'=>'password',
  193. 'size'=>50,
  194. 'maxlength'=>'20',
  195. 'placeholder'=>'minimo 6 caracteres',
  196. );
  197. ?></div>
  198. <div id="pass_1_b"><?php echo form_password($data_form)?></div>
  199.  
  200.  
  201. <div id="pass_2"><?=form_label('Confirmar Pass','password2')?><?php
  202. $data_form=array(
  203. 'name'=>'password2',
  204. 'id'=>'password2',
  205. 'size'=>50,
  206. 'maxlength'=>'20',
  207. 'placeholder'=>'minimo 6 caracteres',
  208. );
  209. ?></div>
  210. <div id="pass_2_b"><?php echo form_password($data_form)?></div>
  211.  
  212.  
  213. <div id="name_r"><?=form_label('Nome','name')?><?php
  214. $data_form=array(
  215. 'id'=>'name',
  216. 'name'=>'name',
  217. 'size'=>50,
  218. 'maxlength'=>'50',
  219. 'placeholder'=>'nome facturação',
  220. );
  221. ?></div>
  222. <div id="name_r_b"><?php echo form_input($data_form)?></div>
  223.  
  224.  
  225. <div id="contact1"><?=form_label('Contacto','contact')?><?php
  226. $data_form=array(
  227. 'id'=>'contact',
  228. 'name'=>'contact',
  229. 'size'=>24,
  230. 'maxlength'=>'9',
  231. 'placeholder'=>'n.º movel ou fixo',
  232. 'style'=>"padding-bottom : 0px;font-size:13px;"
  233. );
  234. ?>
  235. </div>
  236. <div id="contact_b"><?php echo form_input($data_form)?></div>
  237.  
  238.  
  239.  
  240. <div id="pais"><?=form_label('Pais','country');?></div>
  241. <div id="pais_b"><?php echo form_dropdown('country', $country); ?></div>
  242.  
  243.  
  244. <div id="adres"><?=form_label('Morada','address')?><?php
  245. $data_form=array(
  246. 'id'=>'address',
  247. 'name'=>'address',
  248. 'size'=>50,
  249. 'maxlength'=>'50',
  250. 'placeholder'=>'morada de facturação',
  251. );
  252. ?></div><div id="adres_b"><?php echo form_input($data_form)?></div>
  253.  
  254.  
  255. <div id="code"><?=form_label('Codigo Postal','postalCODE')?><?php
  256. $data_form=array(
  257. 'id'=>'postalCODE',
  258. 'name'=>'postalCODE',
  259. 'size'=>6,
  260. 'maxlength'=>'6',
  261. 'placeholder'=>'1111',
  262. );
  263. ?></div>
  264. <div id="code1"><?php echo form_input($data_form)?> /</div>
  265.  
  266. <div id="code22"><?=form_label('','postalCODE2')?><?php
  267. $data_form=array(
  268. 'id'=>'postalCODE2',
  269. 'name'=>'postalCODE2',
  270. 'size'=>5,
  271. 'maxlength'=>'5',
  272. 'placeholder'=>'111',
  273. );
  274. ?></div><div id="code2"><?php echo form_input($data_form)?></div>
  275.  
  276.  
  277.  
  278. <div id="city2"><?=form_label('Localidade','city')?> <?php
  279. $data_form=array(
  280. 'id'=>'city',
  281. 'name'=>'city',
  282. 'size'=>24,
  283. 'maxlength'=>'30',
  284. 'style'=>"padding-bottom : 0px;font-size:13px;",
  285. 'placeholder'=>'localidade facturação',
  286. );
  287. ?></div><div id="city_b"><?php echo form_input($data_form)?></div>
  288.  
  289.  
  290. <div id="number"><?=form_label('N.º Contribuinte','taxpayerNUMBER')?><?php
  291. $data_form=array(
  292. 'id'=>'taxpayerNUMBER',
  293. 'name'=>'taxpayerNUMBER',
  294. 'size'=>24,
  295. 'maxlength'=>'9',
  296. 'placeholder'=>'numero contribuinte valido',
  297. );
  298. ?></div><div id="number_b"><?php echo form_input($data_form)?></div>
  299.  
  300. <div id="botao"><?php echo form_submit('',' Registar '); ?></div>
  301. <?php echo form_close(); ?>
  302.  
  303. </div>
  304.  
  305. if ( ! function_exists('form_dropdown'))
  306. {
  307. function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
  308. {
  309. if ( ! is_array($selected))
  310. {
  311. $selected = array($selected);
  312. }
  313.  
  314. // If no selected state was submitted we will attempt to set it automatically
  315. if (count($selected) === 0)
  316. {
  317. // If the form name appears in the $_POST array we have a winner!
  318. if (isset($_POST[$name]))
  319. {
  320. $selected = array($_POST[$name]);
  321. }
  322. }
  323.  
  324. if ($extra != '') $extra = ' '.$extra;
  325.  
  326. $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
  327.  
  328. $form = '<select name="'.$name.'"'.$extra.$multiple.">n";
  329.  
  330. foreach ($options as $key => $val)
  331. {
  332. $key = (string) $key;
  333.  
  334. if (is_array($val) && ! empty($val))
  335. {
  336. $form .= '<optgroup label="'.$key.'">'."n";
  337.  
  338. foreach ($val as $optgroup_key => $optgroup_val)
  339. {
  340. $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';
  341.  
  342. $form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>n";
  343. }
  344.  
  345. $form .= '</optgroup>'."n";
  346. }
  347. else
  348. {
  349. $sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
  350.  
  351. $form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>n";
  352. }
  353. }
  354.  
  355. $form .= '</select>';
  356.  
  357. return $form;
  358. }
  359. }
  360.  
  361. A PHP Error was encountered
  362. Severity: Notice
  363. Message: Undefined variable: country
  364. Filename: views/login.php
  365. Line Number: 143
  366.  
  367. A PHP Error was encountered
  368. Severity: Warning
  369. Message: Invalid argument supplied for foreach()
  370. Filename: helpers/form_helper.php
  371. Line Number: 331
  372.  
  373. } else {//registo
  374. $data=array(
  375. 'username'=>$_POST['username'],
  376.  
  377. } else {//registo
  378. $additional_data=array(
  379. 'username'=>$_POST['username'],
  380. 'userTYPE'=>'user',
  381. 'password'=>sha1($_POST['password']),
  382. 'email'=>$_POST['email'],
  383. 'active'=>$_POST['newsletter']==null?0:1,
  384. 'name'=>$_POST['name'],
  385. 'contact'=>$_POST['contact'],
  386. 'country'=>$_POST['country'],
  387. 'address'=>$_POST['address'],
  388. 'postalCODE'=>$_POST['postalCODE'],
  389. 'postalCODE2'=>$_POST['postalCODE2'],
  390. 'city'=>$_POST['city'],
  391. 'taxpayerNUMBER'=>$_POST['taxpayerNUMBER']
  392. );
  393. array_merge($data, $additional_data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement