PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/trunk/admin/edits.php

http://bitcero-modules.googlecode.com/
PHP | 395 lines | 293 code | 81 blank | 21 comment | 32 complexity | 10e65b82a39e05beb1f912ddd7d8383a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. // $Id: edits.php 821 2011-12-08 23:46:19Z i.bitcero $
  3. // --------------------------------------------------------------
  4. // Ability Help
  5. // http://www.redmexico.com.mx
  6. // http://www.exmsystem.net
  7. // --------------------------------------------
  8. // @author BitC3R0 <i.bitcero@gmail.com>
  9. // @license: GPL v2
  10. define('RMCLOCATION', 'waiting');
  11. include 'header.php';
  12. /**
  13. * @desc Muestra una lista con los elementos editados esperando aprovación
  14. */
  15. function showEdits(){
  16. global $xoopsModule, $db, $adminTemplate, $tpl, $mc;
  17. $sql = "SELECT * FROM ".$db->prefix("rd_edits");
  18. list($num) = $db->fetchRow($db->query($sql));
  19. $page = rmc_server_var($_REQUEST, 'page', 1);
  20. $limit = 15;
  21. $tpages = ceil($num/$limit);
  22. $page = $page > $tpages ? $tpages : $page;
  23. $start = $num<=0 ? 0 : ($page - 1) * $limit;
  24. $nav = new RMPageNav($num, $limit, $page, 5);
  25. $nav->target_url('edits.php?page={PAGE_NUM}');
  26. $sql = "SELECT * FROM ".$db->prefix("rd_edits")." ORDER BY `modified` DESC LIMIT $start,$limit";
  27. $result = $db->query($sql);
  28. $sections = array();
  29. while ($row = $db->fetchArray($result)){
  30. $edit = new RDEdit();
  31. $edit->assignVars($row);
  32. $sec = new RDSection($edit->getVar('id_sec'));
  33. $sections[] = array(
  34. 'id'=>$edit->id(),
  35. 'section'=>array(
  36. 'id'=>$sec->id(),
  37. 'title'=>$sec->getVar('title'),
  38. 'link'=>$sec->permalink()
  39. ),
  40. 'title'=>$edit->getVar('title'),
  41. 'date'=>RMTimeFormatter::get()->format($edit->getVar('modified'), __('%M% %d%, %Y%', 'docs')),
  42. 'uname'=>$edit->getVar('uname')
  43. );
  44. }
  45. xoops_cp_location("<a href='./'>".$xoopsModule->name()."</a> &raquo; ".__('Waiting Content','docs'));
  46. xoops_cp_header();
  47. RMTemplate::get()->add_local_script('jquery.checkboxes.js', 'rmcommon', 'include');
  48. RMTemplate::get()->add_local_script('admin.js', 'docs', 'include');
  49. RMTemplate::get()->add_style('admin.css', 'docs');
  50. include RMEvents::get()->run_event("docs.waiting.template", RMTemplate::get()->get_template("admin/rd_waiting.php",'module','docs'));
  51. xoops_cp_footer();
  52. }
  53. /**
  54. * @desc Muestra el contenido de las secciones editadas y original para su revisión
  55. */
  56. function reviewEdit(){
  57. global $xoopsModule;
  58. $id = rmc_server_var($_GET, 'id', 0);
  59. if ($id<=0){
  60. redirectMsg('edits.php', __('You have not specified any section!','docs'), 1);
  61. die();
  62. }
  63. $edit = new RDEdit($id);
  64. if ($edit->isNew()){
  65. redirectMsg('edits.php', __('Specified content does not exists!','docs'), 1);
  66. die();
  67. }
  68. $sec = new RDSection($edit->getVar('id_sec'));
  69. if ($sec->isNew()){
  70. redirectMsg('edits.php', __('The section indicated by current element does not exists!','docs'), 1);
  71. die();
  72. }
  73. // Datos de la Sección
  74. $section = array(
  75. 'id'=>$sec->id(),
  76. 'title'=>$sec->getVar('title'),
  77. 'text'=>$sec->getVar('content'),
  78. 'link'=>$sec->permalink(),
  79. 'res'=>$sec->getVar('id_res')
  80. );
  81. // Datos de la Edición
  82. $new_content = array(
  83. 'id'=>$edit->id(),
  84. 'title'=>$edit->getVar('title'),
  85. 'text'=>$edit->getVar('content')
  86. );
  87. xoops_cp_location("<a href='./'>".$xoopsModule->name()."</a> &raquo; <a href='./edits.php'>".__('Waiting Content','docs')."</a> &raquo; ".sprintf(__('Editing %s','docs'), $sec->getVar('title')));
  88. xoops_cp_header();
  89. RMTemplate::get()->add_style('admin.css', 'docs');
  90. include RMEvents::get()->run_event('docs.template.review.waiting', RMTemplate::get()->get_template('admin/rd_reviewedit.php', 'module', 'docs'));
  91. xoops_cp_footer();
  92. }
  93. function approveEdits(){
  94. $edits = isset($_REQUEST['edits']) ? $_REQUEST['edits'] : array();
  95. if (!is_array($edits) && $edits<=0){
  96. redirectMsg('./edits.php', _AS_AH_NOID, 1);
  97. die();
  98. }
  99. $edits = !is_array($edits) ? array($edits) : $edits;
  100. if (count($edits)<=0){
  101. redirectMsg('./edits.php', _AS_AH_NOID, 1);
  102. die();
  103. }
  104. $errors = false;
  105. foreach ($edits as $k){
  106. $edit = new AHEdit($k);
  107. if ($edit->isNew()){
  108. $errors = true;
  109. continue;
  110. }
  111. $sec = new AHSection($edit->section());
  112. if ($sec->isNew()){
  113. $errors = true;
  114. continue;
  115. }
  116. // Guardamos los valores
  117. $sec->setTitle($edit->title());
  118. $sec->setNameId($edit->nameId());
  119. $sec->modified($edit->modified());
  120. $sec->setUid($edit->uid());
  121. $sec->setUname($edit->uname());
  122. $sec->setOrder($edit->order());
  123. $sec->setParent($edit->parent());
  124. $sec->setVar('dohtml', $edit->getVar('dohtml'));
  125. $sec->setVar('doxcode', $edit->getVar('doxcode'));
  126. $sec->setVar('dobr', $edit->getVar('dobr'));
  127. $sec->setVar('doimage', $edit->getVar('doimage'));
  128. $sec->setVar('dosmiley', $edit->getVar('dosmiley'));
  129. $sec->setContent($edit->content());
  130. if (!$sec->save()){
  131. $errors = true;
  132. continue;
  133. }
  134. $edit->delete();
  135. }
  136. if ($errors){
  137. redirectMsg('./edits.php', _AS_AH_ERRORSONAPPROVE, 1);
  138. die();
  139. } else {
  140. redirectMsg('./edits.php', _AS_AH_DBOK, 0);
  141. die();
  142. }
  143. }
  144. function deleteEdits(){
  145. $edits = isset($_REQUEST['edits']) ? $_REQUEST['edits'] : array();
  146. if (!is_array($edits) && $edits<=0){
  147. redirectMsg('./edits.php', _AS_AH_NOID, 1);
  148. die();
  149. }
  150. $edits = !is_array($edits) ? array($edits) : $edits;
  151. if (count($edits)<=0){
  152. redirectMsg('./edits.php', _AS_AH_NOID, 1);
  153. die();
  154. }
  155. $errors = false;
  156. foreach ($edits as $k){
  157. $edit = new AHEdit($k);
  158. if ($edit->isNew()){
  159. $errors = true;
  160. continue;
  161. }
  162. $edit->delete();
  163. }
  164. if ($errors){
  165. redirectMsg('./edits.php', _AS_AH_ERRORSONAPPROVE, 1);
  166. die();
  167. } else {
  168. redirectMsg('./edits.php', _AS_AH_DBOK, 0);
  169. die();
  170. }
  171. }
  172. function showFormEdits(){
  173. global $xoopsModule, $xoopsConfig;
  174. $id = rmc_server_var($_GET, 'id', 0);
  175. if ($id<=0){
  176. redirectMsg('edits.php', __('You have not specified any waiting section!','docs'), 1);
  177. die();
  178. }
  179. $edit = new RDEdit($id);
  180. if ($edit->isNew()){
  181. redirectMsg('edits.php', __('Specified content does not exists!','docs'), 1);
  182. die();
  183. }
  184. $sec = new RDSection($edit->getVar('id_sec'));
  185. if ($sec->isNew()){
  186. redirectMsg('edits.php', __('This waiting content does not have any section assigned!','docs'), 1);
  187. die();
  188. }
  189. $res = new RDResource($sec->getVar('id_res'));
  190. $form=new RMForm(__('Editing Waiting Content','docs'),'frmsec','edits.php');
  191. $form->addElement(new RMFormLabel(__('Belong to','docs'),$res->getVar('title')));
  192. $form->addElement(new RMFormText(__('Title','docs'),'title',50,200,$edit->getVar('title')),true);
  193. $form->addElement(new RMFormEditor(__('Contenido','docs'),'content','90%','300px',$edit->getVar('content', 'e')),true);
  194. // Arbol de Secciones
  195. $ele= new RMFormSelect(__('Parent Section','docs'),'parent');
  196. $ele->addOption(0,__('Select section...','docs'));
  197. $tree = array();
  198. RDFunctions::sections_tree_index(0, 0, $res, '', '', false, $tree, false);
  199. foreach ($tree as $k){
  200. $ele->addOption($k['id'], str_repeat('&#151;', $k['jump']).' '.$k['title'], $edit->getVar('parent')==$k['id'] ? 1 : 0);
  201. }
  202. $form->addElement($ele);
  203. $form->addElement(new RMFormText(__('Display order','docs'),'order',5,5,$edit->getVar('order')),true);
  204. // Usuario
  205. $form->addElement(new RMFormUser(__('Owner','docs'), 'uid', 0, array($edit->getVar('uid')), 30));
  206. $buttons =new RMFormButtonGroup();
  207. $buttons->addButton('sbt',__('Save Now','docs'),'submit');
  208. $buttons->addButton('cancel',__('Cancel','docs'),'button', 'onclick="window.location=\'edits.php\';"');
  209. $form->addElement($buttons);
  210. $form->addElement(new RMFormHidden('action','save'));
  211. $form->addElement(new RMFormHidden('id',$edit->id()));
  212. xoops_cp_location("<a href='./'>".$xoopsModule->name()."</a> &raquo; <a href='./edits.php'>".__('Waiting Content','docs')."</a> &raquo; ".sprintf(__('Editing %s','docs'), $edit->getVar('title')));
  213. xoops_cp_header();
  214. RMTemplate::get()->assign('xoops_pagetitle', __('Editing Waiting Content','docs'));
  215. $form->display();
  216. xoops_cp_footer();
  217. }
  218. function saveEdit(){
  219. global $db, $util, $xoopsUser;
  220. foreach ($_POST as $k => $v){
  221. $$k = $v;
  222. }
  223. if (!$util->validateToken()){
  224. redirectMsg('edits.php?op=edit&id='.$id, _AS_AH_SESSINVALID, 1);
  225. die();
  226. }
  227. if ($id<=0){
  228. redirectMsg('./edits.php', _AS_AH_NOID, 1);
  229. die();
  230. }
  231. $edit = new AHEdit($id);
  232. if ($edit->isNew()){
  233. redirectMsg('./edits.php', _AS_AH_NOTEXISTS, 1);
  234. die();
  235. }
  236. $sec = new AHSection($edit->section());
  237. if ($sec->isNew()){
  238. redirectMsg('./edits.php', _AS_AH_NOTEXISTSSEC, 1);
  239. die();
  240. }
  241. //Comprueba que el título de la sección no exista
  242. $sql="SELECT COUNT(*) FROM ".$db->prefix('pa_sections')." WHERE title='$title' AND id_res='".$sec->resource()."' AND id_sec<>'".$sec->id()."'";
  243. list($num)=$db->fetchRow($db->queryF($sql));
  244. if ($num>0){
  245. redirectMsg('./edits.php?op=edit&id='.$edit->id(), _AS_AH_ERRTITLE,1);
  246. die();
  247. }
  248. //Genera $nameid Nombre identificador
  249. $found=false;
  250. $i = 0;
  251. do{
  252. $nameid = $util->sweetstring($title).($found ? $i : '');
  253. $sql = "SELECT COUNT(*) FROM ".$db->prefix('pa_sections'). " WHERE nameid = '$nameid'";
  254. list ($num) =$db->fetchRow($db->queryF($sql));
  255. if ($num>0){
  256. $found =true;
  257. $i++;
  258. }else{
  259. $found=false;
  260. }
  261. }while ($found==true);
  262. $sec->setTitle($title);
  263. $sec->setContent($content);
  264. $sec->setOrder($order);
  265. $sec->setNameId($nameid);
  266. $sec->setParent($parent);
  267. $sec->setVar('dohtml', isset($dohtml) ? 1 : 0);
  268. $sec->setVar('doxcode', isset($doxcode) ? 1 : 0);
  269. $sec->setVar('dobr', isset($dobr) ? 1 : 0);
  270. $sec->setVar('dosmiley', isset($dosmiley) ? 1 : 0);
  271. $sec->setVar('doimage', isset($dosmiley) ? 1 : 0);
  272. if (!isset($uid)){
  273. $sec->setUid($xoopsUser->uid());
  274. $sec->setUname($xoopsUser->uname());
  275. } else {
  276. $xu = new XoopsUser($uid);
  277. if ($xu->isNew()){
  278. $sec->setUid($xoopsUser->uid());
  279. $sec->setUname($xoopsUser->uname());
  280. } else {
  281. $sec->setUid($uid);
  282. $sec->setUname($xu->uname());
  283. }
  284. }
  285. $sec->setModified(time());
  286. if (!$sec->save()){
  287. redirectMsg('edits.php', _AS_AH_DBERROR . '<br />' . $sec->errors(), 1);
  288. die();
  289. }
  290. $edit->delete();
  291. redirectMsg('edits.php', _AS_AH_DBOK, 0);
  292. }
  293. $action = rmc_server_var($_REQUEST, 'action', '');
  294. switch($action){
  295. case 'review':
  296. reviewEdit();
  297. break;
  298. case 'approve':
  299. approveEdits();
  300. break;
  301. case 'edit':
  302. showFormEdits();
  303. break;
  304. case 'save':
  305. saveEdit();
  306. break;
  307. case 'delete':
  308. deleteEdits();
  309. break;
  310. default:
  311. showEdits();
  312. break;
  313. }
  314. ?>