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

Documentation generated on Thu, 20 Mar 2014 16:49:07 +0100 by phpDocumentor 1.4.1