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.  *
  14.  * @param string $string 
  15.  * @param string $type 
  16.  * @return string $requete
  17.  */
  18. function SQL_project_search($string$type)
  19. {
  20.  
  21.   if ($type == 'PUBLIC'{
  22.     $date 'project_published_date';
  23.     $statut_mask 'AND project_statut<>\'E\' AND project_statut<>\'AA\' AND project_statut<>\'D\'';
  24.   }
  25.   if ($type == 'ADMIN'{
  26.     $date 'project_date_crea';
  27.     $statut_mask 'AND project_statut<>\'E\'';
  28.   }
  29.   $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;';
  30.  
  31.   return $requete;
  32. }
  33.  
  34. /**
  35.  * SQL_news_search()
  36.  *
  37.  * @param string $string 
  38.  * @param string $type 
  39.  * @return string $requete
  40.  */
  41. function SQL_news_search($string$type)
  42. {
  43.  
  44.   if ($type == 'PUBLIC'{
  45.     $date 'news_published_date';
  46.     $statut_mask 'AND news_statut<>\'E\' AND news_statut<>\'AA\' AND news_statut<>\'D\'';
  47.   }
  48.   if ($type == 'ADMIN'{
  49.     $date 'news_date_crea';
  50.     $statut_mask 'AND news_statut<>\'E\'';
  51.   }
  52.   $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;';
  53.  
  54.   return $requete;
  55. }
  56.  
  57. /**
  58.  * SQL_newsletter_search()
  59.  *
  60.  * @param string $string 
  61.  * @param string $type 
  62.  * @return string $requete
  63.  */
  64. function SQL_newsletter_search($string$type)
  65. {
  66.   if ($type == 'PUBLIC'{
  67.     $date 'newsletter_published_date';
  68.     $statut_mask 'AND newsletter_statut<>\'E\' AND newsletter_statut<>\'D\'';
  69.   }
  70.   if ($type == 'ADMIN'{
  71.     $date 'newsletter_date_crea';
  72.     $statut_mask 'AND newsletter_statut<>\'E\'';
  73.   }
  74.   $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;';
  75.  
  76.   return $requete;
  77. }
  78.  
  79. /**
  80.  * SQL_publication_search()
  81.  *
  82.  * @param string $string 
  83.  * @param string $type 
  84.  * @return string $requete
  85.  */
  86. function SQL_publication_search($string$type)
  87. {
  88.   if ($type == 'PUBLIC'{
  89.     $date 'publi_published_date';
  90.     $statut_mask 'AND publi_statut<>\'E\' AND publi_statut<>\'AA\' AND publi_statut<>\'D\'';
  91.   }
  92.   if ($type == 'ADMIN'{
  93.     $date 'publi_date_crea';
  94.     $statut_mask 'AND publi_statut<>\'E\'';
  95.   }
  96.   $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;';
  97.  
  98.   return $requete;
  99. }
  100.  
  101. /**
  102.  * SQL_publication_content_search()
  103.  *
  104.  * @param string $string 
  105.  * @param string $type 
  106.  * @return string $requete
  107.  */
  108. function SQL_publication_content_search($string$type)
  109. {
  110.   if ($type == 'PUBLIC'{
  111.     $date 'publi_published_date';
  112.     $statut_mask 'AND publi_statut<>\'E\' AND publi_statut<>\'AA\' AND publi_statut<>\'D\' AND publicon_validity=\'Y\'';
  113.   }
  114.   if ($type == 'ADMIN'{
  115.     $date 'publi_date_crea';
  116.     $statut_mask 'AND publi_statut<>\'E\' AND publicon_validity=\'Y\'';
  117.   }
  118.   $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;';
  119.  
  120.   return $requete;
  121. }
  122.  
  123. /**
  124.  * SQL_sdi_search()
  125.  *
  126.  * @param string $string 
  127.  * @param string $type 
  128.  * @return string $requete
  129.  */
  130. function SQL_sdi_search($string$type)
  131. {
  132.   if ($type == 'PUBLIC'{
  133.     $statut_mask 'AND sdii_statut<>\'D\' AND sdii_statut<>\'E\'';
  134.   }
  135.   if ($type == 'ADMIN'{
  136.     $statut_mask 'AND sdii_statut<>\'E\'';
  137.   }
  138.   $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;';
  139.  
  140.   return $requete;
  141. }
  142.  
  143. /**
  144.  * SQL_workshop_search()
  145.  *
  146.  * @param string $string 
  147.  * @param string $type 
  148.  * @return string $requete
  149.  */
  150. function SQL_workshop_search($string$type)
  151. {
  152.   if ($type == 'PUBLIC'{
  153.     $date 'workshop_date_crea';
  154.     $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\'';
  155.   }
  156.   if ($type == 'ADMIN'{
  157.     $date 'workshop_date_crea';
  158.     $statut_mask 'AND workshop_statut<>\'E\'';
  159.   }
  160.   $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;';
  161.  
  162.   return $requete;
  163. }
  164.  
  165. /**
  166.  * SQL_workshop_content_search()
  167.  *
  168.  * @param string $string 
  169.  * @param string $type 
  170.  * @return string $requete
  171.  */
  172. function SQL_workrep_search($string$type)
  173. {
  174.   if ($type == 'PUBLIC'{
  175.     $date 'workrep_published_date';
  176.     $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\'';
  177.   }
  178.   if ($type == 'ADMIN'{
  179.     $date 'workrep_date_crea';
  180.     $statut_mask 'AND workshop_statut<>\'E\' AND workrep_statut<>\'E\'';
  181.   }
  182.   $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;';
  183.  
  184.   return $requete;
  185. }
  186.  
  187. /**
  188.  * SQL_workshop_content_search()
  189.  *
  190.  * @param string $string 
  191.  * @param string $type 
  192.  * @return string $requete
  193.  */
  194. function SQL_workrep_content_search($string$type)
  195. {
  196.   if ($type == 'PUBLIC'{
  197.     $date 'workrep_date_crea';
  198.     $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\'';
  199.   }
  200.   if ($type == 'ADMIN'{
  201.     $date 'workrep_date_crea';
  202.     $statut_mask 'AND workshop_statut<>\'E\' AND workrep_statut<>\'E\' AND workrepcon_validity=\'Y\'';
  203.   }
  204.   $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;';
  205.  
  206.   return $requete;
  207. }
  208.  
  209. /**
  210.  * SQL_workshop_content_search()
  211.  *
  212.  * @param string $string 
  213.  * @param string $type 
  214.  * @return string $requete
  215.  */
  216. function SQL_workshop_calendar_search($string$type)
  217. {
  218.   if ($type == 'PUBLIC'{
  219.     $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workcal_validity=\'Y\'';
  220.   }
  221.   if ($type == 'ADMIN'{
  222.     $statut_mask 'AND workshop_statut<>\'E\' AND workcal_validity=\'Y\'';
  223.   }
  224.  
  225.   $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;';
  226.  
  227.   return $requete;
  228. }
  229.  
  230. /**
  231.  * SQL_workshop_content_search()
  232.  *
  233.  * @param string $string 
  234.  * @param string $type 
  235.  * @return string $requete
  236.  */
  237. function SQL_workshop_com_search($string$type)
  238. {
  239.   if ($type == 'PUBLIC'{
  240.     $statut_mask 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workcom_statut <>\'E\'';
  241.   }
  242.   if ($type == 'ADMIN'{
  243.     $statut_mask 'AND workshop_statut<>\'E\' AND workcom_statut <>\'E\'';
  244.   }
  245.  
  246.   $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;';
  247.  
  248.   return $requete;
  249. }
  250.  
  251. /**
  252.  * SQL_yellowpages_search()
  253.  *
  254.  * @param string $string 
  255.  * @param string $type 
  256.  * @param string $searchtype 
  257.  * @return string $requete
  258.  */
  259. function SQL_yellowpages_search($string$type$searchtype)
  260. {
  261.   if ($type == 'PUBLIC'{
  262.     $statut_mask 'AND yellowp_statut<>\'E\' AND yellowp_statut<>\'AA\' AND yellowp_statut<>\'D\'';
  263.   }
  264.   if ($type == 'ADMIN'{
  265.     $statut_mask 'AND yellowp_statut<>\'E\'';
  266.   }
  267.   $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;';
  268.  
  269.   return $requete;
  270. }
  271.  
  272. /**
  273.  * SQL_user_search()
  274.  *
  275.  * @param string $string 
  276.  * @param string $type 
  277.  * @param string $searchtype 
  278.  * @return string $requete
  279.  */
  280. function SQL_user_search($string$type$searchtype)
  281. {
  282.   if ($type == 'PUBLIC'{
  283.     $statut_mask 'AND user_validity<>\'D\' AND user_validity<>\'N\'';
  284.   }
  285.   if ($type == 'ADMIN'{
  286.     $statut_mask 'AND user_validity<>\'N\'';
  287.   }
  288.   $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;';
  289.  
  290.   return $requete;
  291. }
  292.  
  293. /**
  294.  * SQL_theme_search()
  295.  *
  296.  * @param string $string 
  297.  * @param string $type 
  298.  * @param string $searchtype 
  299.  * @return string $requete
  300.  */
  301. function SQL_theme_search($string$type$searchtype)
  302. {
  303.   if ($type == 'PUBLIC'{
  304.     $statut_mask 'AND theme_statut<>\'D\' AND theme_statut<>\'E\'';
  305.   }
  306.   if ($type == 'ADMIN'{
  307.     $statut_mask 'AND theme_statut<>\'E\'';
  308.   }
  309.   $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;';
  310.  
  311.   return $requete;
  312. }
  313.  
  314. /**
  315.  * SQL_scale_search()
  316.  *
  317.  * @param string $string 
  318.  * @param string $type 
  319.  * @param string $searchtype 
  320.  * @return string $requete
  321.  */
  322. function SQL_scale_search($string$type$searchtype)
  323. {
  324.   if ($type == 'PUBLIC'{
  325.     $statut_mask 'AND scale_statut<>\'D\' AND scale_statut<>\'E\' AND scale_statut<>\'I\'';
  326.   }
  327.   if ($type == 'ADMIN'{
  328.     $statut_mask 'AND scale_statut<>\'I\' AND scale_statut<>\'E\'';
  329.   }
  330.   $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;';
  331.  
  332.   return $requete;
  333. }
  334.  
  335. /**
  336.  * SQL_level_search()
  337.  *
  338.  * @param string $string 
  339.  * @param string $type 
  340.  * @param string $searchtype 
  341.  * @return string $requete
  342.  */
  343. function SQL_level_search($string$type$searchtype)
  344. {
  345.   if ($type == 'PUBLIC'{
  346.     $statut_mask 'AND level_statut<>\'D\' AND level_statut<>\'E\'';
  347.   }
  348.   if ($type == 'ADMIN'{
  349.     $statut_mask 'AND level_statut<>\'E\'';
  350.   }
  351.   $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;';
  352.  
  353.   return $requete;
  354. }
  355.  
  356. /**
  357.  * SQL_ConstructorExpression()
  358.  * Construit les requĂȘtes simple
  359.  *
  360.  * @param string $string 
  361.  * @param string $searchtype 
  362.  * @param string $field_name 
  363.  * @return string $requete
  364.  */
  365. function SQL_ConstructorExpression($string$searchtype$field_name)
  366. {
  367.   $clause_requete 'WHERE ';
  368.   $sep '';
  369.   $string trim($string);
  370.   $strings @explode(' '$string);
  371.   switch ($searchtype{
  372.     case 'one':
  373.       for($i 0$i count($strings)$i++{
  374.         if(strlen($strings[$i])<=3)    $clause_requete .= $sep $field_name ' LIKE \'' $strings[$i'%\'';
  375.         else $clause_requete .= $sep $field_name ' LIKE \'%' $strings[$i'%\'';
  376.         $sep ' OR ';
  377.       }
  378.       break;
  379.     case 'all':
  380.       for($i 0$i count($strings)$i++{
  381.         if(strlen($strings[$i])<=3$clause_requete .= $sep $field_name ' LIKE \'' $strings[$i'%\'';
  382.         else $clause_requete .= $sep $field_name ' LIKE \'%' $strings[$i'%\'';
  383.         $sep ' AND ';
  384.       }
  385.       break;
  386.     case 'exp':
  387.       $clause_requete .= $field_name '=\'' $string '\'';
  388.       break;
  389.     default:
  390.       $clause_requete .= $field_name ' LIKE \'%' $string '%\'';
  391.       break;
  392.   }
  393.   return $clause_requete;
  394. }
  395.  
  396. ?>

Documentation generated on Fri, 01 Apr 2011 09:33:29 +0200 by phpDocumentor 1.4.1