WYSIJA_view_back

The MailPoet Newsletters WYSIJA view back class.

Defined (1)

The class is defined in the following location(s).

/views/back.php  
  1. class WYSIJA_view_back extends WYSIJA_view{ 
  2.  
  3. var $column_actions=array();/**list of actions possible through links in the list*/ 
  4. var $column_action_list='';/**name of the column that will contain the list of action*/ 
  5. var $arrayMenus=array(); 
  6. var $bulks=array(); 
  7. var $action=''; 
  8. var $statuses=array(); 
  9. var $skip_header = false; // simply returns the wrapper if true 
  10. var $listingHeader = ''; 
  11. var $hiddenFields = ''; 
  12.  
  13. function __construct() { 
  14. /** the default actions to be linked in a listing */ 
  15. if(!$this->column_actions) $this->column_actions=array('view'=>__('View', WYSIJA), 'edit'=>__('Edit', WYSIJA), 'delete'=>__('Delete', WYSIJA)); 
  16.  
  17. $this->bulks["delete"]=array("name"=>__("Delete", WYSIJA)); 
  18.  
  19. /** 
  20. * creation of a generic listing view 
  21. * @param type $data 
  22. */ 
  23. function main($data) { 
  24.  
  25. echo '<form method="post" action="admin.php?page='. esc_attr($_REQUEST['page']).'" id="posts-filter">'; 
  26. $this->filtersLink(); 
  27. $this->searchBox(); 
  28.  
  29. $this->listing($data); 
  30. echo '</form>'; 
  31.  
  32. function menuTop($actionmenu=false) { 
  33.  
  34. $menu=""; 
  35. if(!empty($this->arrayMenus)) { 
  36. foreach($this->arrayMenus as $action =>$actiontrans) { 
  37. $menu.= '<a href="admin.php?page='. esc_attr($_REQUEST['page']).'&action='.$action.'" class="button-secondary2">'.$actiontrans.'</a>'; 
  38.  
  39. return $menu; 
  40.  
  41. /** 
  42. * to help reproduce the standard view of wordpress admin view here is the header part 
  43. * @param type $methodView 
  44. */ 
  45. function header($data='') { 
  46. echo '<div id="wysija-app" class="wrap">';/**start div class wrap*/ 
  47.  
  48. if($this->skip_header === true) return; 
  49.  
  50. $header = '<div class="icon32" id="'.$this->icon.'"><br/></div>'; 
  51. $full_title = __($this->title, WYSIJA); 
  52. $action = $sub_title = ''; 
  53.  
  54. if( isset($_REQUEST['action']) ) { 
  55. $action = $_REQUEST['action']; 
  56.  
  57. if(isset($this->titlelink)) { 
  58. $my_title = '<a href="admin.php?page='. esc_attr($_REQUEST['page']).'">'.$full_title.'</a> '; 
  59. }else{ 
  60. $my_title = $full_title . ' '; 
  61.  
  62. $header .= '<h2>'.$my_title.$sub_title.$this->menuTop($this->action, $data).'</h2>'; 
  63. $header .= $this->messages(); 
  64.  
  65. echo $header; 
  66.  
  67.  
  68.  
  69. /** 
  70. * to help reproduce the standard view of wordpress admin view here is the footer part 
  71. */ 
  72. function footer() { 
  73. echo '</div>';/**end div class wrap*/ 
  74.  
  75. /** 
  76. * to help reproduce the standard listing of a wordpress admin, here is the list of links appearing on top 
  77. */ 
  78. function filtersLink() { 
  79. if($this->statuses) { 
  80. ?> 
  81. <div class="filter"> 
  82. <ul class="subsubsub"> 
  83. <?php 
  84.  
  85. $last_key = key(array_slice($this->statuses, -1, 1, TRUE)); 
  86.  
  87. foreach($this->statuses as $keyst=>$status) { 
  88. $class=''; 
  89. if(isset($_REQUEST['link_filter']) && $_REQUEST['link_filter'] === $status['key']) $class='current'; 
  90.  
  91. // set item count: defaults to 0 
  92. $count = (isset($status['count'])) ? (int)$status['count'] : 0; 
  93.  
  94. if(isset($status['uri'])) { 
  95. echo '<li><a class="'.$class.'" href="'.$status['uri'].'">'.$status['title'].' <span class="count">('.$count.')</span></a>'; 
  96. } else { 
  97. echo '<li><a class="'.$class.'" href="javascript:;">'.$status['title'].' <span class="count">('.$count.')</span></a>'; 
  98. if($last_key!=$keyst) echo ' | '; 
  99. echo '</li>'; 
  100.  
  101. ?> 
  102. </ul> 
  103. </div> 
  104. <?php 
  105.  
  106. /** 
  107. * to help reproduce the standard listing of a wordpress admin, here is the search box 
  108. */ 
  109. function searchBox() { 
  110. $search=""; 
  111. if(isset($_REQUEST['search'])) $search =stripslashes($_REQUEST['search']); 
  112. ?> 
  113. <p class="search-box"> 
  114. <label for="wysija-search-input" class="screen-reader-text"><?php echo $this->search['title'] ?></label> 
  115. <input type="text" value="<?php echo esc_attr($search) ?>" class="searchbox" name="search" id="wysija-search-input"> 
  116. <input type="submit" class="searchsub button" value="<?php echo esc_attr($this->search['title']) ?>"> 
  117. </p> 
  118. <?php 
  119.  
  120. /** 
  121. * to help reproduce the standard listing of a wordpress admin, here is the table header/footer of the listing 
  122. * @param type $data 
  123. * @return type 
  124. */ 
  125. function buildHeaderListing($data) { 
  126. //building the headers labels 
  127. if(!$data) { 
  128. //$this->notice(__("There is no data at the moment.", WYSIJA)); 
  129. return false; 
  130. $this->listingHeader='<tr class="thead">'; 
  131. $columns=$data[0]; 
  132. $sorting=array(); 
  133. //dbg($columns); 
  134. foreach($columns as $row =>$colss) { 
  135. $sorting[$row]=" sortable desc"; 
  136. if(isset($_REQUEST["orderby"]) && $_REQUEST["orderby"]==$row) $sorting[$row]=" sorted ".$_REQUEST["ordert"]; 
  137.  
  138. $hiddenOrder=""; 
  139. if(isset($_REQUEST["orderby"])) { 
  140. $hiddenOrder='<input type="hidden" name="orderby" id="wysija-orderby" value="'.esc_attr($_REQUEST["orderby"]).'"/>'; 
  141. $hiddenOrder.='<input type="hidden" name="ordert" id="wysija-ordert" value="'.esc_attr($_REQUEST["ordert"]).'"/>'; 
  142. $nk=false; 
  143. if(isset($columns[$this->model->pk])) { 
  144. $nk=str_replace("_", '-', $this->model->pk); 
  145. unset($columns[$this->model->pk]); 
  146. $this->cols_nks[$this->model->pk]=$nk; 
  147.  
  148. if($this->bulks) { 
  149. if($nk) { 
  150. $this->listingHeader='<th class="manage-column column-'.$nk.' check-column" id="'.$nk.'" scope="col"><input type="checkbox"></th>'; 
  151.  
  152. foreach($columns as $key => $value) { 
  153. $nk=str_replace("_", '-', $key); 
  154. $this->listingHeader.='<th class="manage-column column-'.$nk.$sorting[$key].'" id="'.$nk.'" scope="col">'; 
  155.  
  156. if(isset($this->model->columns[$key]['label'])) $label=$this->model->columns[$key]['label']; 
  157. else $label=ucfirst($key); 
  158. $this->listingHeader.='<a class="orderlink" href="#"><span>'.$label.'</span><span class="sorting-indicator"></span></a>'; 
  159.  
  160. $this->listingHeader.='</th>'; 
  161.  
  162. $this->cols_nks[$key]=$value; 
  163. $this->hiddenFields=$hiddenOrder; 
  164. $this->listingHeader.='</tr>'; 
  165. return $this->listingHeader; 
  166.  
  167.  
  168. /** 
  169. * to help reproduce the standard listing of a wordpress admin, here is the bulk action dropdown applied to selected rows 
  170. */ 
  171. function globalActions($data=false, $second=false) { 
  172. ?> 
  173. <div class="tablenav"> 
  174. <?php if($this->bulks) { ?> 
  175. <div class="alignleft actions"> 
  176. <select name="action2" class="global-action"> 
  177. <option selected="selected" value=""><?php echo esc_attr(__('Bulk Actions', WYSIJA)); ?></option> 
  178. <?php 
  179. foreach($this->bulks as $key=> $bulk) { 
  180. echo '<option value="bulk_'.$key.'">'.$bulk['name'].'</option>'; 
  181. ?> 
  182. </select> 
  183. <input type="submit" class="bulksubmit button-secondary action" name="doaction" value="<?php echo esc_attr(__('Apply', WYSIJA)); ?>"> 
  184. <?php if(!$second)$this->secure('bulk_delete'); ?> 
  185. </div> 
  186. <?php } ?> 
  187. <?php $this->pagination('', $second); ?> 
  188. <div class="clear"></div> 
  189. </div> 
  190. <?php 
  191.  
  192.  
  193. // Pagination for listing pages. 
  194. function pagination($paramsurl='', $second=false) { 
  195.  
  196. $number_of_pages = 1; 
  197. $number_of_pages = ceil($this->model->countRows/$this->model->limit); 
  198.  
  199. echo '<div class="tablenav-pages">'; 
  200.  
  201. $current_page = 1; 
  202. if (isset($_REQUEST['pagi'])) { 
  203. $current_page = (int)$_REQUEST['pagi']; 
  204.  
  205. if ($number_of_pages > 1) { 
  206.  
  207. // Pagination input box to manually enter the page requested. 
  208. $pagination_input = ""; 
  209. $suffix = ""; 
  210. if ($second) { 
  211. $suffix = "-2"; 
  212. $pagination_input = '<input id="wysija-pagination' . $suffix . '" type="text" name="pagi' . $suffix . '" size="4" value="' . $current_page . '" />'; 
  213. $pagination_input .= '<input id="wysija-pagination-max' . $suffix . '" type="hidden" name="pagimax' . $suffix . '" value="' . $number_of_pages . '" />'; 
  214.  
  215. // Final pagination container. 
  216. $pagi = ''; 
  217.  
  218. // Pagination Previous Arrows. 
  219. if ($current_page != 1) { 
  220. $pagi .= '<a class="prev page-numbers" href="admin.php?page='.esc_attr($_REQUEST['page']).'&pagi=1'.$paramsurl.'" alt="1" title="'.sprintf(__('Page %1$s', WYSIJA), 1).'">«</a>'; 
  221. if ($current_page>2) { 
  222. $pagi .= '<a class="prev page-numbers" href="admin.php?page='.esc_attr($_REQUEST['page']).'&pagi='.($current_page-1).$paramsurl.'" alt="'.($current_page-1).'" title="'.sprintf(__('Page %1$s', WYSIJA), ($current_page-1)).'" >‹</a>'; 
  223.  
  224. // Input field and total pages. 
  225. $pagi .= $pagination_input; 
  226. $pagi.= '<span class="total-pages">' . sprintf(__('of %1$s', WYSIJA), $number_of_pages) . '</span>'; 
  227.  
  228. // Pagination Next arrows. 
  229. if($number_of_pages > 1 && $current_page != $number_of_pages) { 
  230. if (($number_of_pages - $current_page) >= 2) { 
  231. $pagi .= '<a class="next page-numbers" href="admin.php?page='.esc_attr($_REQUEST['page']).'&pagi='.($current_page+1).$paramsurl.'" alt="'.($current_page+1).'" title="'.sprintf(__('Page %1$s', WYSIJA), ($current_page+1)).'">›</a>'; 
  232. $pagi .= '<a class="next page-numbers" href="admin.php?page='.esc_attr($_REQUEST['page']).'&pagi='.$number_of_pages.$paramsurl.'" alt="'.$number_of_pages.'" title="'.sprintf(__('Page %1$s', WYSIJA), $number_of_pages).'" >»</a>'; 
  233.  
  234. echo $pagi; 
  235.  
  236.  
  237. echo '</div>'; 
  238.  
  239.  
  240.  
  241.  
  242. /** 
  243. * limit of records to show per page 
  244. */ 
  245. function limitPerPage() { 
  246. $limitPerpageS=array(5, 10, 20, 50, 100); 
  247. if($this->model->countRows <= $limitPerpageS[0]) return true; 
  248. $limitPerpage=array(); 
  249.  
  250. foreach($limitPerpageS as $k => $count) { 
  251. $limitPerpage[] = $count; 
  252. if($this->model->countRows < $count) break; 
  253. if(!$limitPerpage) return; 
  254.  
  255. $pagi=''; 
  256. if(isset($this->limit_pp)) $pagi.='<input id="wysija-pagelimit" type="hidden" name="limit_pp" value="'.$this->limit_pp.'" />'; 
  257. foreach($limitPerpage as $k => $count) { 
  258. $numperofpages=ceil($this->model->countRows/$count); 
  259. $titleLink=' title="'.(isset($this->viewObj->title) ? $this->viewObj->title : sprintf(__('Split subscribers into %1$s pages.', WYSIJA), $numperofpages)).'" '; 
  260. /**if($urlbase) $linkk=$urlbase.'&limit_pp='.$count; 
  261. else $linkk='admin.php?page='.$_REQUEST['page'].'&limit_pp='.$count;*/ 
  262. $linkk='javascript:;'; 
  263. if(isset($_REQUEST['limit_pp'])) { 
  264. if($_REQUEST['limit_pp']==$count) $pagi.='<span '.$titleLink.' class="page-limit current">'.$count.'</span>'; 
  265. else $pagi.='<a href="'.$linkk.'" '.$titleLink.' class="page-limit" >'.$count.'</a>'; 
  266. }else{ 
  267.  
  268. if($this->model->limit==$count) $pagi.='<span class="page-limit current" '.$titleLink.' >'.$count.'</span>'; 
  269. else $pagi.='<a href="'.$linkk.'" '.$titleLink.' class="page-limit" >'.$count.'</a>'; 
  270. if($k+1 < count($limitPerpage)) $pagi.=" | "; 
  271. ?> 
  272. <div class="tablenav-limits subsubsub"> 
  273. <span class="displaying-limits"><?php 
  274. if(isset($this->viewObj->msgPerPage)) { 
  275. echo $this->viewObj->msgPerPage; 
  276. }else{ 
  277. _e('Subscribers to show per page:', WYSIJA); 
  278. ?></span> 
  279. <?php 
  280. echo $pagi; 
  281. ?> 
  282. </div> 
  283. <?php 
  284.  
  285.  
  286.  
  287.  
  288. /** 
  289. * here is a helper for each column value on a listing view 
  290. * @param type $key 
  291. * @param type $val 
  292. * @param type $type 
  293. * @return type 
  294. */ 
  295. function fieldListHTML($key, $val, $params=array()) { 
  296. /**get the params of that field if there is*/ 
  297. $field_type = (isset($params['type']) ? $params['type'] : ''); 
  298.  
  299. switch($field_type) { 
  300. case 'pk': 
  301. return '<th class="check-column" scope="col"><input class="checkboxselec" type="checkbox" value="'.$val.'" id="'.$key.'_'.$val.'" name="wysija['.$this->model->table_name.']['.$key.'][]"></th>'; 
  302. break; 
  303. case 'boolean': 
  304.  
  305. $wrap='<td class="'.$key.' column-'.$key.'">'; 
  306. $wrap.=$params['values'][$val]; 
  307. $wrap.='</td>'; 
  308.  
  309. break; 
  310. case 'date': 
  311.  
  312. $wrap='<td class="'.$key.' column-'.$key.'">'; 
  313. $wrap.=$this->fieldListHTML_created_at($val); 
  314. $wrap.='</td>'; 
  315.  
  316. break; 
  317. case 'time': 
  318.  
  319. if(!isset($params['format']))$params['format']=''; 
  320.  
  321. $wrap='<td class="'.$key.' column-'.$key.'">'; 
  322. $wrap.=$this->fieldListHTML_created_at($val, $params['format']); 
  323. $wrap.='</td>'; 
  324.  
  325. break; 
  326. default: 
  327. $wrap='<td class="column-'.$key.'">'; 
  328. $specialMethod="fieldListHTML_".$key; 
  329. if(method_exists($this, $specialMethod)) $wrap.=$this->$specialMethod($val); 
  330. else $wrap.=$val; 
  331.  
  332. $wrap.=$this->getActionLinksList($key); 
  333.  
  334. $wrap.='</td>'; 
  335.  
  336. return $wrap; 
  337.  
  338. /** 
  339. * this function adds a list of action links under the column valued in a listing 
  340. * @param type $column 
  341. * @return string 
  342. */ 
  343. function getActionLinksList($column, $manual=false) { 
  344. $wrap=''; 
  345. if($this->column_action_list==$column ||$manual) { 
  346. $wrap='<div class="row-actions">'; 
  347. end($this->column_actions); 
  348. $lastkey=key($this->column_actions); 
  349. reset($this->column_actions); 
  350. foreach($this->column_actions as $action => $title) { 
  351. switch($action) { 
  352. case "delete": 
  353. $noncefield='&_wpnonce='.$this->secure(array('action'=>$action, 'id'=>$this->valPk), true); 
  354. break; 
  355. default: 
  356. $noncefield=""; 
  357. $separator=''; 
  358.  
  359. if($action!=$lastkey) $separator=' | '; 
  360.  
  361. if(!isset($this->model->model_name)) $this->model->model_name=$this->model->table_name; 
  362. if(!isset($this->model->model_prefix)) $this->model->model_prefix=$this->model->table_prefix; 
  363. $wrap.='<span class="'.$action.'"> 
  364. <a href="admin.php?page='.$this->model->model_prefix.'_'.$this->model->model_name.'&id='.$this->valPk.'&action='.$action.$noncefield.'" class="submit'.$action.'">'.$title.'</a>'.$separator.' 
  365. </span>'; 
  366.  
  367.  
  368. $wrap.='</div>'; 
  369. return $wrap; 
  370.  
  371.  
  372. /** 
  373. * this function is here to help in generic forms 
  374. * @param type $key 
  375. * @param type $val 
  376. * @param type $type 
  377. * @return type 
  378. */ 
  379. function fieldFormHTML($key, $wrapped) { 
  380. if(isset($this->model->columns[$key]['label'])) $label=$this->model->columns[$key]['label']; 
  381. else $label=ucfirst($key); 
  382. $desc=''; 
  383. if(isset($this->model->columns[$key]['desc'])) $desc='<p class="description">'.$this->model->columns[$key]['desc'].'</p>'; 
  384. $wrap='<th scope="row"> 
  385. <label for="'.$key.'">'.$label.$desc.' </label> 
  386. </th><td>'; 
  387.  
  388. $wrap.=$wrapped; 
  389. $wrap.='</td>'; 
  390. return $wrap; 
  391.  
  392. function buildMyForm($form_fields, $data, $model, $required=false) { 
  393.  
  394. $form_html = ''; 
  395. foreach($form_fields as $form_key =>$col_params) { 
  396. $class = $value = ''; 
  397. $params_column = false; 
  398. if(isset($col_params['rowclass'])) $class = ' class="'.$col_params['rowclass'].'" '; 
  399. if(isset($col_params['row_id'])) $class.= ' id="'.$col_params['row_id'].'" '; 
  400. $form_html .= '<tr '.$class.'>'; 
  401. if($model == 'config') { 
  402. $value = $this->model->getValue($form_key); 
  403. }else{ 
  404. if($form_key != 'lists') { 
  405. if(is_array($model)) { 
  406. foreach($model as $mod) { 
  407. if(isset($data[$mod][$form_key])) { 
  408. $value=$data[$mod][$form_key]; 
  409. break; 
  410. }else{ 
  411. if(isset($col_params['isparams'])) { 
  412. $params=$data[$model][$col_params['isparams']]; 
  413.  
  414. $value=''; 
  415. if(isset($params[$form_key])) $value=$params[$form_key]; 
  416. $params_column=$col_params['isparams']; 
  417. if(isset($data[$model][$form_key])) $value=$data[$model][$form_key]; 
  418. if($value) $value; 
  419. elseif(isset($_REQUEST['wysija'][$this->model->table_name][$form_key])) $value=$_REQUEST['wysija'][$this->model->table_name][$form_key]; 
  420. elseif(isset($col_params['default'])) $value=$col_params['default']; 
  421. else $value=''; 
  422. }elseif(isset($data[$form_key])) $value=$data[$form_key]; 
  423. elseif(isset($col_params['default'])) $value=$col_params['default']; 
  424. else $value=''; 
  425.  
  426. if($required && !isset($col_params['class'])) $col_params['class']=$this->getClassValidate($this->model->columns[$form_key], true); 
  427.  
  428. if(isset($col_params['label'])) $label=$col_params['label']; 
  429. else $label=ucfirst($form_key); 
  430. $desc=''; 
  431. if(isset($col_params['desc'])) { 
  432. if(isset($col_params['link'])) $col_params['desc']=str_replace(array('[link]', '[/link]'), array($col_params['link'], '</a>'), $col_params['desc']); 
  433. $desc='<p class="description">'.$col_params['desc'].'</p>'; 
  434.  
  435. $colspan=' colspan="2" '; 
  436. if(!isset($col_params['1col'])) { 
  437. $form_html.='<th scope="row">'; 
  438. if(!isset($col_params['labeloff'])) $form_html.='<label for="'.$form_key.'">'; 
  439. $form_html.=$label.$desc; 
  440. if(!isset($col_params['labeloff'])) $form_html.=' </label>'; 
  441. $form_html.='</th>'; 
  442. $colspan=''; 
  443. $form_html.='<td '.$colspan.'>'; 
  444. $form_html.=$this->fieldHTML($form_key, $value, $model, $col_params, $params_column); 
  445. $form_html.='</td>'; 
  446.  
  447. $form_html.='</tr>'; 
  448. return $form_html; 
  449. /** 
  450. * @param type $key 
  451. * @param type $val 
  452. * @param type $type 
  453. * @return type 
  454. */ 
  455. function fieldHTML($key, $val='', $model='', $params=array(), $paramscolumn=false) { 
  456. $classValidate=$wrap=''; 
  457. // get the params of that field if there is 
  458. $type=$params['type']; 
  459. // js validator class setup 
  460. if($params) $classValidate=$this->getClassValidate($params); 
  461.  
  462. if($paramscolumn) { 
  463. $col=$paramscolumn.']['.$key; 
  464. }else $col=$key; 
  465.  
  466. $id_field=$key; 
  467. if(isset($params['id'])) { 
  468. $id_field=$params['id']; 
  469. $field_name='wysija['.$model.']['.$col.']'; 
  470. $helper_forms=WYSIJA::get('forms', 'helper'); 
  471. switch($type) { 
  472. case 'pk': 
  473. return '<input type="hidden" value="'.$val.'" id="'.$id_field.'" name="'.$field_name.'">'; 
  474. break; 
  475. case 'boolean': 
  476.  
  477. $wrap.=$helper_forms->dropdown(array('id'=>$id_field, 'name'=>$field_name), $params['values'], $val, $classValidate); 
  478. break; 
  479. case 'roles': 
  480. $wptools=WYSIJA::get('wp_tools', 'helper'); 
  481. $editable_roles=$wptools->wp_get_editable_roles(); 
  482.  
  483. $wrap.=$helper_forms->dropdown(array('id'=>$id_field, 'name'=>$field_name), $editable_roles, $val, $classValidate); 
  484. break; 
  485. case 'password': 
  486. if(!isset($params['size'])) { 
  487. $classValidate.=' size="80"'; 
  488. }else { 
  489. $classValidate.=' size="'.$params['size'].'"'; 
  490.  
  491. $wrap.=$helper_forms->input(array('type'=>'password', 'id'=>$id_field, 'name'=>$field_name), $val, $classValidate); 
  492. break; 
  493. case 'disabled_radio': 
  494.  
  495. $wrap.=$helper_forms->radios(array('id'=>$id_field, 'name'=>$field_name, 'disabled'=>'disabled'), $params['values'], $val, $classValidate); 
  496. break; 
  497. case 'radio': 
  498.  
  499. $wrap.=$helper_forms->radios(array('id'=>$id_field, 'name'=>$field_name), $params['values'], $val, $classValidate); 
  500. break; 
  501. case 'dropdown_keyval': 
  502. $newoption=array(); 
  503. foreach($params['values'] as $vall) { 
  504. $newoption[$vall]=$vall; 
  505.  
  506. $wrap.=$helper_forms->dropdown(array('id'=>$id_field, 'name'=>$field_name), $newoption, $val, $classValidate); 
  507. break; 
  508. case 'dropdown': 
  509.  
  510. $wrap.=$helper_forms->dropdown(array('id'=>$id_field, 'name'=>$field_name), $params['values'], $val, $classValidate); 
  511. break; 
  512. case 'wysija_pages_list': 
  513. $wrapd=get_pages( array('post_type'=>"wysijap", 'echo'=>0, 'name'=>$field_name, 'id'=>$id_field, 'selected' => $val, 'class'=>$classValidate) ); 
  514.  
  515. break; 
  516. case 'pages_list': 
  517. $wrap.=wp_dropdown_pages( array('echo'=>0, 'name'=>$field_name, 'id'=>$id_field, 'selected' => $val, 'class'=>$classValidate) ); 
  518. break; 
  519. default: 
  520. if(!isset($params['size'])) { 
  521. $classValidate.=' size="80"'; 
  522. }else{ 
  523. $classValidate.=' size="'.$params['size'].'"'; 
  524. if(isset($params['class'])) { 
  525. $classValidate.=' class="'.$params['class'].'"'; 
  526.  
  527. $specialMethod='fieldFormHTML_'.$type; 
  528.  
  529. if(method_exists($this, $specialMethod)) $wrap.=$this->$specialMethod($key, $val, $model, $params); 
  530. else{ 
  531.  
  532. if(method_exists($helper_forms, $type)) { 
  533. $dataInput=array('id'=>$id_field, 'name'=>$field_name); 
  534. if(isset($params['cols']))$dataInput['cols']=$params['cols']; 
  535. if(isset($params['rows']))$dataInput['rows']=$params['rows']; 
  536. $wrap.=$helper_forms->$type($dataInput, $val, $classValidate); 
  537. }else{ 
  538. $wrap.=$helper_forms->input(array('id'=>$id_field, 'name'=>$field_name), $val, $classValidate); 
  539. return $wrap; 
  540.  
  541. /** 
  542. * this function is the default listing function 
  543. * @param type $data 
  544. */ 
  545. function listing($data, $simple=false) { 
  546.  
  547. if(!$simple) $this->globalActions(); 
  548.  
  549. $html='<table cellspacing="0" class="widefat fixed"> 
  550. <thead>'; 
  551. $html.=$this->buildHeaderListing($data); 
  552. $html.='</thead>'; 
  553.  
  554. $html.='<tfoot>'; 
  555. $html.=$this->listingHeader; 
  556. $html.='</tfoot>'; 
  557.  
  558. $html.='<tbody class="list:'.$this->model->table_name.' '.$this->model->table_name.'-list" id="wysija-'.$this->model->table_name.'" >'; 
  559.  
  560. $listingRows=''; 
  561. $alt=true; 
  562. foreach($data as $row =>$columns) { 
  563. $classRow=''; 
  564. if($alt) $classRow=' class="alternate" '; 
  565. $listingRows.='<tr'.$classRow.' id="'.$this->model->table_name.'-'.$this->model->table_name.'">'; 
  566. $valpkcol=false; 
  567. if(isset($columns[$this->model->pk])) { 
  568. $this->valPk=$columns[$this->model->pk]; 
  569. $valpkcol=$this->model->columns[$this->model->pk]; 
  570. $this->model->columns[$this->model->pk]['type']='pk'; 
  571. unset($columns[$this->model->pk]); 
  572. if($this->bulks) { 
  573.  
  574. if($valpkcol) { 
  575. $listingRows.=$this->fieldListHTML($this->model->pk, $this->valPk, $this->model->columns[$this->model->pk]); 
  576.  
  577.  
  578.  
  579. foreach($columns as $key => $value) { 
  580. if(isset($this->model->columns[$key])) $val=$this->model->columns[$key]; 
  581. else $val=''; 
  582. $listingRows.=$this->fieldListHTML($key, $value, $val); 
  583. $listingRows.='</th>'; 
  584. $alt=!$alt; 
  585. $html.= $listingRows; 
  586.  
  587.  
  588.  
  589. $html.=' </tbody> 
  590. </table>'; 
  591. if(!$simple) echo $html; 
  592. if(!$simple) { 
  593. $this->globalActions(false, true); 
  594. $this->limitPerPage(); 
  595. echo $this->hiddenFields; 
  596.  
  597. if($simple) return $html; 
  598.  
  599. /** 
  600. * here is a generic form view 
  601. * @param type $data 
  602. */ 
  603. function edit($data) { 
  604.  
  605. $formid='wysija-'.$_REQUEST['action']; 
  606. if($_REQUEST['action']=="edit") { 
  607. $buttonName=__('Modify', WYSIJA); 
  608. }else{ 
  609. $buttonName=__('Add', WYSIJA); 
  610.  
  611. ?> 
  612.  
  613. <form name="<?php echo $formid ?>" method="post" id="<?php echo $formid ?>" action="" class="form-valid"> 
  614.  
  615. <table class="form-table"> 
  616. <tbody> 
  617. <?php 
  618. foreach($data as $row =>$columns) { 
  619. $formFields='<tr>'; 
  620. if(isset($columns[$this->model->pk])) { 
  621. $this->valPk=$columns[$this->model->pk]; 
  622. $this->model->columns[$this->model->pk]['type']="pk"; 
  623. $formFields.=$this->fieldHTML($this->model->pk, $this->valPk, $this->model->table_name, $this->model->columns[$this->model->pk ]); 
  624. unset($columns[$this->model->pk]); 
  625. foreach($columns as $key => $value) { 
  626. $formFields.=$this->fieldFormHTML($key, $this->fieldHTML($key, $value, $this->model->table_name, $this->model->columns[$key])); 
  627. $formFields.='</tr>'; 
  628. echo $formFields; 
  629. ?> 
  630. </tbody> 
  631. </table> 
  632. <p class="submit"> 
  633. <?php $this->secure(array('action'=>"save", 'id'=> $this->valPk)); ?> 
  634. <input type="hidden" value="save" name="action" /> 
  635. <input type="submit" value="<?php echo esc_attr($buttonName); ?>" class="button-primary wysija"> 
  636. </p> 
  637. </form> 
  638. <?php 
  639.  
  640. /** 
  641. * here is a generic form view 
  642. * @param type $data 
  643. */ 
  644. function view($data, $echo=true) { 
  645.  
  646. $html=' <table class="form-table"> 
  647. <tbody>'; 
  648. foreach($data as $row =>$columns) { 
  649. $formFields='<tr>'; 
  650.  
  651. foreach($columns as $key => $value) { 
  652. $formFields.=$this->fieldFormHTML($key, $value); 
  653. $formFields.='</tr>'; 
  654. $html.= $formFields; 
  655.  
  656. $html.=' </tbody> 
  657. </table>'; 
  658.  
  659. if($echo) echo $html; 
  660. else return $html; 
  661.  
  662. function fieldFormHTML_fromname($key, $val, $model, $params) { 
  663. $formObj=WYSIJA::get('forms', 'helper'); 
  664. $disableEmail=false; 
  665. if($model!='config') $model='email'; 
  666. if($key=='from_name') $keyemail='from_email'; 
  667. else $keyemail='replyto_email'; 
  668.  
  669. //$dataInputEmail=array('class'=>'validate[required]', 'id'=>$keyemail, 'name'=>"wysija[$model][$keyemail]", 'size'=>40); 
  670. $dataInputEmail=array('class'=>'validate[required, custom[email]]', 'id'=>$keyemail, 'name'=>"wysija[$model][$keyemail]", 'size'=>40); 
  671.  
  672. if(isset($this->data['email'][$key])) { 
  673. $valname=$this->data['email'][$key]; 
  674. $valemail=$this->data['email'][$keyemail]; 
  675. }else{ 
  676. $valname=$this->model->getValue($key); 
  677. $valemail=$this->model->getValue($keyemail); 
  678.  
  679. //if from email and sending method is gmail then the email is blocked to the smtp_login 
  680. if($key=='from_name') { 
  681. $modelConfig=WYSIJA::get('config', 'model'); 
  682. switch($modelConfig->getValue('sending_method')) { 
  683. case 'gmail': 
  684. $dataInputEmail['readonly']='readonly'; 
  685. $dataInputEmail['class']='disabled'; 
  686. $valemail=$modelConfig->getValue('smtp_login'); 
  687.  
  688. //if the user didn't enter the email address then we put it ourself 
  689. if(strpos($valemail, '@')===false && strpos($valemail, '@gmail.com')===false) { 
  690. $valemail.='@gmail.com'; 
  691. $from_name_field=$formObj->input($dataInputEmail , $valemail); 
  692. break; 
  693. case 'network': 
  694. $from_name_field='  '.$modelConfig->getValue('ms_from_email').$formObj->hidden($dataInputEmail , $valemail); 
  695. break; 
  696. default : 
  697. $from_name_field=$formObj->input($dataInputEmail , $valemail); 
  698.  
  699. }else{ 
  700. $from_name_field=$formObj->input($dataInputEmail , $valemail); 
  701.  
  702.  
  703. $fieldHtml=$formObj->input( array('class'=>'validate[required]', 'id'=>$key, 'name'=>"wysija[$model][$key]"), $valname); 
  704. $fieldHtml.=$from_name_field; 
  705. return $fieldHtml; 
  706.  
  707. function _savebuttonsecure($data, $action="save", $button=false, $warning=false) { 
  708. if(!$button) $button=__("Save", WYSIJA); 
  709. ?> 
  710. <p class="submit"> 
  711. <?php 
  712.  
  713. $secure=array('action'=>$action); 
  714. if(isset($data[$this->model->table_name][$this->model->pk])) $secure["id"]=$data[$this->model->table_name][$this->model->pk]; 
  715. $this->secure($secure); ?> 
  716. <input type="hidden" name="wysija[<?php echo $this->model->table_name ?>][<?php echo $this->model->pk ?>]" id="<?php echo $this->model->pk ?>" value="<?php if(isset($data[$this->model->table_name][$this->model->pk])) echo esc_attr($data[$this->model->table_name][$this->model->pk]) ?>" /> 
  717. <input type="hidden" value="<?php echo $action ?>" name="action" /> 
  718. <input type="submit" id="next-steptmpl" value="<?php echo esc_attr($button) ?>" name="submit-draft" class="button-primary wysija"/> 
  719. <?php if($warning) echo $warning; ?> 
  720. </p> 
  721. <?php 
  722.