reviser.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2014 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined("_ECRIRE_INC_VERSION")) return;
  12. include_spip('base/abstract_sql');
  13. function trouver_version_inf($objet,$id_objet,$cond=""){
  14. return sql_getfetsel(
  15. 'id_version',
  16. 'spip_versions',
  17. ($cond?"$cond AND ":"")."objet=".sql_quote($objet)." AND id_objet=".intval($id_objet),
  18. '',
  19. 'id_version DESC',
  20. '0,1'
  21. );
  22. }
  23. function check_version_diff($objet, $id_objet, $id_version, $id_diff, $last_version=0){
  24. if (!$last_version)
  25. $last_version = trouver_version_inf($objet,$id_objet);
  26. // si pas de diff possible, on renvoi 0,0
  27. if (!$last_version)
  28. return array(0,0);
  29. if ($last_version==1)
  30. return array(1,0);
  31. $id_version = max($id_version,2);
  32. $id_version = min($id_version,$last_version);
  33. // verifier id_version
  34. $id_version = trouver_version_inf($objet,$id_objet,"id_version<=".intval($id_version));
  35. // si rien trouve on prend la derniere
  36. if (!$id_version)
  37. $id_version = $last_version;
  38. // minorer id_diff en fonction de id_version
  39. $id_diff = min($id_diff,$id_version-1);
  40. // verifier id_diff
  41. $id_diff = trouver_version_inf($objet,$id_objet,"id_version<=".intval($id_diff));
  42. if (!$id_diff)
  43. $id_diff = trouver_version_inf($objet,$id_objet,"id_version<".intval($id_version));
  44. // echec, on renvoi ce qu'on peut
  45. if (!$id_diff)
  46. $id_diff = $id_version-1;
  47. return array($id_version, $id_diff);
  48. }
  49. function formulaires_reviser_charger_dist($objet,$id_objet,$id_version,$id_diff){
  50. if (!$objets = unserialize($GLOBALS['meta']['objets_versions']))
  51. $objets = array();
  52. if (!in_array(table_objet_sql($objet),$objets))
  53. return false;
  54. $last_version = trouver_version_inf($objet,$id_objet);
  55. list($id_version,$id_diff) = check_version_diff($objet,$id_objet,$id_version,$id_diff,$last_version);
  56. if (!$id_version)
  57. return false;
  58. $valeurs = array(
  59. '_last_version'=>$last_version,
  60. '_objet'=>$objet,
  61. '_id_objet'=>$id_objet,
  62. 'id_version'=>$id_version,
  63. 'id_diff'=>$id_diff,
  64. );
  65. return $valeurs;
  66. }
  67. function formulaires_reviser_verifier_dist($objet,$id_objet,$id_version,$id_diff){
  68. $erreurs = array();
  69. list($id_version,$id_diff) = check_version_diff($objet,$id_objet,_request('id_version'),_request('id_diff'));
  70. set_request('id_version',$id_version);
  71. set_request('id_diff',$id_diff);
  72. return $erreurs;
  73. }
  74. function formulaires_reviser_traiter_dist($objet,$id_objet,$id_version,$id_diff){
  75. $res = array('message_ok'=>'','editable'=>true);
  76. $id_version = _request('id_version');
  77. $id_diff = _request('id_diff');
  78. if (_AJAX)
  79. $res['message_ok'].="<script type='text/javascript'>if (window.jQuery) jQuery('#wysiwyg.revision').ajaxReload({args:{id_version:$id_version,id_diff:$id_diff},history:true});</script>";
  80. else
  81. $res['redirect'] = parametre_url(parametre_url(self(),'id_version',$id_version),'id_diff',$id_diff,'&');
  82. return $res;
  83. }