linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file mysql.inc.php

Documentation is available at mysql.inc.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage search
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11. /**
  12. * SQL_project_search()
  13. @param string $string 
  14. @param string $type 
  15. @return string $requete
  16. */
  17. function SQL_project_search($string$type)
  18. {
  19.  
  20.     if ($type == 'PUBLIC'{
  21.         $date 'project_published_date';
  22.         $statut_mask 'AND project_statut<>\'E\' AND project_statut<>\'AA\' AND project_statut<>\'D\'';
  23.     
  24.     if ($type == 'ADMIN'{
  25.         $date 'project_date_crea';
  26.         $statut_mask 'AND project_statut<>\'E\'';
  27.     
  28.     $requete 'SELECT project_id, project_name, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, project_statut AS statut, MATCH(project_name, project_description, project_body) AGAINST(\'' $string '\') AS pertinence FROM ' T_PROJECT ' WHERE MATCH (project_name, project_description, project_body) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  29.  
  30.     return $requete;
  31. }
  32.  
  33. /**
  34. * SQL_news_search()
  35. @param string $string 
  36. @param string $type 
  37. @return string $requete
  38. */
  39. function SQL_news_search($string$type)
  40. {
  41.  
  42.     if ($type == 'PUBLIC'{
  43.         $date 'news_published_date';
  44.         $statut_mask 'AND news_statut<>\'E\' AND news_statut<>\'AA\' AND news_statut<>\'D\'';
  45.     
  46.     if ($type == 'ADMIN'{
  47.         $date 'news_date_crea';
  48.         $statut_mask 'AND news_statut<>\'E\'';
  49.     
  50.     $requete 'SELECT news_id, news_title, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, news_statut AS statut, MATCH(news_title, news_header, news_body) AGAINST(\'' $string '\') AS pertinence FROM ' T_NEWS ' WHERE MATCH (news_title, news_header, news_body) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  51.  
  52.     return $requete;
  53. }
  54.  
  55. /**
  56. * SQL_newsletter_search()
  57. @param string $string 
  58. @param string $type 
  59. @return string $requete
  60. */
  61. function SQL_newsletter_search($string$type)
  62. {
  63.     if ($type == 'PUBLIC'{
  64.         $date 'newsletter_published_date';
  65.         $statut_mask 'AND newsletter_statut<>\'E\' AND newsletter_statut<>\'D\'';
  66.     
  67.     if ($type == 'ADMIN'{
  68.         $date 'newsletter_date_crea';
  69.         $statut_mask 'AND newsletter_statut<>\'E\'';
  70.     
  71.     $requete 'SELECT newsletter_id, newsletter_title, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, newsletter_statut AS statut, MATCH(newsletter_title, newsletter_body) AGAINST(\'' $string '\') AS pertinence FROM ' T_NEWSLETTER ' WHERE MATCH (newsletter_title, newsletter_body) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  72.  
  73.     return $requete;
  74.  
  75. /**
  76. * SQL_publication_search()
  77. @param string $string 
  78. @param string $type 
  79. @return string $requete
  80. */
  81. function SQL_publication_search($string$type)
  82. {
  83.     if ($type == 'PUBLIC'{
  84.         $date 'publi_published_date';
  85.         $statut_mask 'AND publi_statut<>\'E\' AND publi_statut<>\'AA\' AND publi_statut<>\'D\'';
  86.     
  87.     if ($type == 'ADMIN'{
  88.         $date 'publi_date_crea';
  89.         $statut_mask 'AND publi_statut<>\'E\'';
  90.     
  91.     $requete 'SELECT publi_id, publi_title, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, publi_statut AS statut, MATCH(publi_title, publi_resume) AGAINST(\'' $string '\') AS pertinence FROM ' T_PUBLI ' WHERE MATCH (publi_title, publi_resume) AGAINST (\'' $string '\' IN BOOLEAN MODE) AND publi_statut<>\'E\' ' $statut_mask ' ORDER BY pertinence DESC;';
  92.  
  93.     return $requete;
  94.  
  95. /**
  96. * SQL_publication_content_search()
  97. @param string $string 
  98. @param string $type 
  99. @return string $requete
  100. */
  101. function SQL_publication_content_search($string$type)
  102. {
  103.     if ($type == 'PUBLIC'{
  104.         $date 'publi_published_date';
  105.         $statut_mask 'AND publi_statut<>\'E\' AND publi_statut<>\'AA\' AND publi_statut<>\'D\' AND publicon_validity=\'Y\'';
  106.     
  107.     if ($type == 'ADMIN'{
  108.         $date 'publi_date_crea';
  109.         $statut_mask 'AND publi_statut<>\'E\' AND publicon_validity=\'Y\'';
  110.     
  111.     $requete 'SELECT publi_id, publi_title, publicon_id, publicon_title, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, publi_statut AS statut, MATCH(publicon_title, publicon_body) AGAINST(\'' $string '\') AS pertinence FROM ' J_PARTS ' LEFT OUTER JOIN ' T_PUBLI_CONT ' ON j_parts_id  =  publicon_id LEFT OUTER JOIN  ' T_PUBLI ' ON  j_root_id= publi_id WHERE MATCH (publicon_title, publicon_body) AGAINST (\'' $string '\' IN BOOLEAN MODE) AND j_type=\'P\' ' $statut_mask ' ORDER BY pertinence DESC;';
  112.  
  113.     return $requete;
  114.  
  115. /**
  116. * SQL_sdi_search()
  117. @param string $string 
  118. @param string $type 
  119. @return string $requete
  120. */
  121. function SQL_sdi_search($string$type)
  122. {
  123.     if ($type == 'PUBLIC'{
  124.         $statut_mask 'AND sdii_statut<>\'D\' AND sdii_statut<>\'E\'';
  125.     
  126.     if ($type == 'ADMIN'{
  127.         $statut_mask 'AND sdii_statut<>\'E\'';
  128.     
  129.     $requete 'SELECT sdii_id, sdii_name, DATE_FORMAT(sdii_date_crea, \''.toStringSqlDate().'\') AS date_display, sdii_statut AS statut, MATCH(sdii_name, sdii_description, sdii_goal, sdii_consulting) AGAINST(\'' $string '\') AS pertinence FROM ' T_SDI_INFO ' WHERE MATCH ( sdii_name, sdii_description, sdii_goal, sdii_consulting) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  130.  
  131.     return $requete;
  132.  
  133. /**
  134. * SQL_workshop_search()
  135. @param string $string 
  136. @param string $type 
  137. @return string $requete
  138. */
  139. function SQL_workshop_search($string$type)
  140. {
  141.     if ($type == 'PUBLIC'{
  142.         $date 'workshop_date_crea';
  143.         $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\'';
  144.     
  145.     if ($type == 'ADMIN'{
  146.         $date 'workshop_date_crea';
  147.         $statut_mask 'AND workshop_statut<>\'E\'';
  148.     
  149.     $requete 'SELECT workshop_id, workshop_denomination, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, workshop_statut AS statut, MATCH(workshop_denomination, workshop_resume) AGAINST(\'' $string '\') AS pertinence FROM ' T_WORK ' WHERE MATCH ( workshop_denomination, workshop_resume) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  150.  
  151.     return $requete;
  152.  
  153. /**
  154. * SQL_workshop_content_search()
  155. @param string $string 
  156. @param string $type 
  157. @return string $requete
  158. */
  159. function SQL_workrep_search($string$type)
  160. {
  161.     if ($type == 'PUBLIC'{
  162.         $date 'workrep_published_date';
  163.         $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workrep_statut<>\'E\' AND workrep_statut<>\'AA\' AND workrep_statut<>\'D\'';
  164.     
  165.     if ($type == 'ADMIN'{
  166.         $date 'workrep_date_crea';
  167.         $statut_mask 'AND workshop_statut<>\'E\' AND workrep_statut<>\'E\'';
  168.     
  169.     $requete 'SELECT workrep_id, workrep_title, workshop_id, workshop_denomination, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, workrep_statut AS statut, MATCH(workrep_title, workrep_resume) AGAINST(\'' $string '\') AS pertinence FROM ' T_WORK_REP ' LEFT OUTER JOIN ' T_WORK ' ON workrep_workshop_id  =  workshop_id WHERE MATCH (workrep_title, workrep_resume) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  170.  
  171.     return $requete;
  172.  
  173. /**
  174. * SQL_workshop_content_search()
  175. @param string $string 
  176. @param string $type 
  177. @return string $requete
  178. */
  179. function SQL_workrep_content_search($string$type)
  180. {
  181.     if ($type == 'PUBLIC'{
  182.         $date 'workrep_date_crea';
  183.         $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workrep_statut<>\'E\' AND workrep_statut<>\'AA\' AND workrep_statut<>\'D\' AND workrepcon_validity=\'Y\'';
  184.     
  185.     if ($type == 'ADMIN'{
  186.         $date 'workrep_date_crea';
  187.         $statut_mask 'AND workshop_statut<>\'E\' AND workrep_statut<>\'E\' AND workrepcon_validity=\'Y\'';
  188.     
  189.     $requete 'SELECT workrep_id, workrep_title, workrepcon_id, workrepcon_title, DATE_FORMAT(' $date ', \''.toStringSqlDate().'\') AS date_display, workrep_statut AS statut, MATCH(workrepcon_title, workrepcon_body) AGAINST(\'' $string '\') AS pertinence FROM ' J_PARTS ' LEFT OUTER JOIN ' T_WORK_REP ' ON j_root_id  =  workrep_id LEFT OUTER JOIN ' T_WORK_REP_CONT ' ON  j_parts_id= workrepcon_id LEFT OUTER JOIN ' T_WORK ' ON workrep_workshop_id  =  workshop_id WHERE MATCH (workrepcon_title, workrepcon_body) AGAINST (\'' $string '\' IN BOOLEAN MODE) AND j_type=\'W\' ' $statut_mask ' ORDER BY pertinence DESC;';
  190.  
  191.     return $requete;
  192.  
  193. /**
  194. * SQL_workshop_content_search()
  195. @param string $string 
  196. @param string $type 
  197. @return string $requete
  198. */
  199. function SQL_workshop_calendar_search($string$type)
  200. {
  201.     if ($type == 'PUBLIC'{
  202.         $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workcal_validity=\'Y\'';
  203.     
  204.     if ($type == 'ADMIN'{
  205.         $statut_mask 'AND workshop_statut<>\'E\' AND workcal_validity=\'Y\'';
  206.     
  207.  
  208.     $requete 'SELECT workcal_id, workcal_task, workcal_workshop_id, workshop_denomination, workshop_statut AS statut, MATCH(workcal_task, workcal_task_details) AGAINST(\'' $string '\') AS pertinence FROM ' T_WORK_CAL ' LEFT OUTER JOIN ' T_WORK ' ON  workcal_workshop_id  = workshop_id WHERE MATCH (workcal_task, workcal_task_details) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  209.  
  210.     return $requete;
  211.  
  212. /**
  213. * SQL_workshop_content_search()
  214. @param string $string 
  215. @param string $type 
  216. @return string $requete
  217. */
  218. function SQL_workshop_com_search($string$type)
  219. {
  220.     if ($type == 'PUBLIC'{
  221.         $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workcom_statut <>\'E\'';
  222.     
  223.     if ($type == 'ADMIN'{
  224.         $statut_mask 'AND workshop_statut<>\'E\' AND workcom_statut <>\'E\'';
  225.     
  226.  
  227.     $requete 'SELECT workcom_id, workcom_parent, workcom_subject, workcom_workshop_id, workshop_denomination, workshop_statut AS statut, MATCH(workcom_subject, workcom_body) AGAINST(\'' $string '\') AS pertinence FROM ' T_WORK_COM ' LEFT OUTER JOIN ' T_WORK ' ON  workcom_workshop_id  = workshop_id WHERE MATCH (workcom_subject, workcom_body) AGAINST (\'' $string '\' IN BOOLEAN MODE) ' $statut_mask ' ORDER BY pertinence DESC;';
  228.  
  229.     return $requete;
  230.  
  231. /**
  232. * SQL_yellowpages_search()
  233. @param string $string 
  234. @param string $type 
  235. @param string $searchtype 
  236. @return string $requete
  237. */
  238. function SQL_yellowpages_search($string$type$searchtype)
  239. {
  240.     if ($type == 'PUBLIC'{
  241.         $statut_mask 'AND yellowp_statut<>\'E\' AND yellowp_statut<>\'AA\' AND yellowp_statut<>\'D\'';
  242.     
  243.     if ($type == 'ADMIN'{
  244.         $statut_mask 'AND yellowp_statut<>\'E\'';
  245.     
  246.     $requete 'SELECT yellowp_id, yellowp_name, DATE_FORMAT(yellowp_date_crea, \''.toStringSqlDate().'\') AS date_display, yellowp_statut AS statut FROM ' T_YELLOWPAGES ' ' SQL_ConstructorExpression($string$searchtype'yellowp_name'' ' $statut_mask ' ORDER BY yellowp_name ASC;';
  247.  
  248.     return $requete;
  249.  
  250. /**
  251. * SQL_user_search()
  252. @param string $string 
  253. @param string $type 
  254. @param string $searchtype 
  255. @return string $requete
  256. */
  257. function SQL_user_search($string$type$searchtype)
  258. {
  259.     if ($type == 'PUBLIC'{
  260.         $statut_mask 'AND user_validity<>\'D\' AND user_validity<>\'N\'';
  261.     
  262.     if ($type == 'ADMIN'{
  263.         $statut_mask 'AND user_validity<>\'N\'';
  264.     
  265.     $requete 'SELECT user_id, user_login, DATE_FORMAT(user_date_crea, \''.toStringSqlDate().'\') AS date_display, user_validity AS statut FROM ' T_USER ' ' SQL_ConstructorExpression($string$searchtype'user_login'' ' $statut_mask ' ORDER BY user_login ASC;';
  266.  
  267.     return $requete;
  268.  
  269. /**
  270. * SQL_theme_search()
  271. @param string $string 
  272. @param string $type 
  273. @param string $searchtype 
  274. @return string $requete
  275. */
  276. function SQL_theme_search($string$type$searchtype)
  277. {
  278.     if ($type == 'PUBLIC'{
  279.         $statut_mask 'AND theme_statut<>\'D\' AND theme_statut<>\'E\'';
  280.     
  281.     if ($type == 'ADMIN'{
  282.         $statut_mask 'AND theme_statut<>\'E\'';
  283.     
  284.     $requete 'SELECT theme_id, theme_name, DATE_FORMAT(theme_date_crea, \''.toStringSqlDate().'\') AS date_display, theme_statut AS statut FROM ' T_THEME ' ' SQL_ConstructorExpression($string$searchtype'theme_name'' ' $statut_mask ' ORDER BY theme_name ASC;';
  285.  
  286.     return $requete;
  287.  
  288. /**
  289. * SQL_scale_search()
  290. @param string $string 
  291. @param string $type 
  292. @param string $searchtype 
  293. @return string $requete
  294. */
  295. function SQL_scale_search($string$type$searchtype)
  296. {
  297.     if ($type == 'PUBLIC'{
  298.         $statut_mask 'AND scale_statut<>\'D\' AND scale_statut<>\'E\' AND scale_statut<>\'I\'';
  299.     
  300.     if ($type == 'ADMIN'{
  301.         $statut_mask 'AND scale_statut<>\'I\' AND scale_statut<>\'E\'';
  302.     
  303.     $requete 'SELECT scale_id, scale_denomination, DATE_FORMAT(scale_date_crea, \''.toStringSqlDate().'\') AS date_display, scale_statut AS statut FROM ' T_SCALE ' ' SQL_ConstructorExpression($string$searchtype'scale_denomination'' ' $statut_mask ' ORDER BY scale_denomination ASC;';
  304.  
  305.     return $requete;
  306.  
  307. /**
  308. * SQL_level_search()
  309. @param string $string 
  310. @param string $type 
  311. @param string $searchtype 
  312. @return string $requete
  313. */
  314. function SQL_level_search($string$type$searchtype)
  315. {
  316.     if ($type == 'PUBLIC'{
  317.         $statut_mask 'AND level_statut<>\'D\' AND level_statut<>\'E\'';
  318.     
  319.     if ($type == 'ADMIN'{
  320.         $statut_mask 'AND level_statut<>\'E\'';
  321.     
  322.     $requete 'SELECT level_id, level_name, DATE_FORMAT(level_date_crea, \''.toStringSqlDate().'\') AS date_display, level_statut AS statut FROM ' T_LEVEL ' ' SQL_ConstructorExpression($string$searchtype'level_name'' ' $statut_mask ' ORDER BY level_name ASC;';
  323.  
  324.     return $requete;
  325.  
  326. /**
  327. * SQL_ConstructorExpression()
  328. * Construit les requĂȘtes simple
  329. @param string $string 
  330. @param string $searchtype 
  331. @param string $field_name 
  332. @return string $requete
  333. */
  334. function SQL_ConstructorExpression($string$searchtype$field_name)
  335. {
  336.     $clause_requete 'WHERE ';
  337.     $sep '';
  338.     $string trim($string);
  339.     $strings @explode(' '$string);
  340.     switch ($searchtype{
  341.         case 'one':
  342.             for($i 0$i count($strings)$i++{
  343.                 if(strlen($strings[$i])<=3)    $clause_requete .= $sep $field_name ' LIKE \'' $strings[$i'%\'';
  344.                 else $clause_requete .= $sep $field_name ' LIKE \'%' $strings[$i'%\'';
  345.                 $sep ' OR ';
  346.             
  347.             break;
  348.         case 'all':
  349.             for($i 0$i count($strings)$i++{
  350.                 if(strlen($strings[$i])<=3$clause_requete .= $sep $field_name ' LIKE \'' $strings[$i'%\'';
  351.                 else $clause_requete .= $sep $field_name ' LIKE \'%' $strings[$i'%\'';
  352.                 $sep ' AND ';
  353.             
  354.             break;
  355.         case 'exp':
  356.             $clause_requete .= $field_name '=\'' $string '\'';
  357.             break;
  358.         default:
  359.             $clause_requete .= $field_name ' LIKE \'%' $string '%\'';
  360.             break;
  361.     
  362.     return $clause_requete;
  363.  
  364. ?>

Documentation generated on Fri, 16 Oct 2009 09:37:40 +0200 by phpDocumentor 1.4.1