Ignore:
Timestamp:
Nov 6, 2009, 1:41:47 PM (14 years ago)
Author:
LucMorizur
Message:

[Event Cats] All DB entries tools OK (tested).

Remains "only" account duplication management, and help and translation

Location:
extensions/event_cats/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/event_cats/include/evntcats_admin_funcs.inc.php

    r4218 r4219  
    201201 */
    202202function ec_create_modify_entry_OK() {
    203   global $page, $ec_lists;
     203  global $page, $ec_lists, $ec_debug;
    204204 
    205205  // $_POST validity checks : action prevented in case of bad arguments
     
    208208   return ec_end1('ec_act1', 'ec_bad_argument1');
    209209 
    210   if (!isset($_POST['ec_input_action']))
    211    return ec_end1('ec_input_action', 'ec_bad_argument1');
     210  if (
     211    ($_POST['ec_act1']) != 'toggle_forced' and
     212    !isset($_POST['ec_input_action'])
     213  ) return ec_end1('ec_input_action', 'ec_bad_argument1');
    212214 
    213215  $is_creation = true;
     216  $ec_user_id = 'NULL';
    214217  $action = 'ec_ok';
    215   $arg1 = '';
    216   $arg2 = '';
     218  $del_other = false;
    217219  switch ($_POST['ec_act1']) {
    218220   
     
    238240    case 'modify_entry_submit':
    239241     
    240       $ec_user_id = '';
    241242      if (isset($_POST['ec_sel_user'])) {
    242243        if ($_POST['ec_sel_user'] == 'new') {
     
    259260      else $action = 'ec_nok';
    260261     
    261      if ($_POST['ec_act1'] == 'create') break;
    262      
    263       $is_creation = false;
     262    if ($_POST['ec_act1'] == 'create') break;
    264263     
    265264    case 'duplicate_entry_submit':
     
    270269      ) return ec_end1('ec_entry_sel', 'ec_bad_argument5');
    271270     
    272      if ($_POST['ec_act1'] == 'modify_entry_submit') break;
     271      if ($_POST['ec_act1'] == 'modify_entry_submit') if (
     272        !isset($_POST['ec_sel_user']) or (
     273          $_POST['ec_sel_user'] == 'new' or
     274          $_POST['ec_sel_user'] == 'none' or (
     275            $_POST['ec_sel_user'] == 'old' and
     276            $_POST['ec_in_up_usr_list'] !=
     277             $ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id']
     278          )
     279        )
     280      ) $del_other = true;
     281     
     282    case 'toggle_forced':
     283     
     284      $ec_code    = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code'];
     285      if ($action == 'ec_ok' and $ec_user_id == 'NULL')
     286       $ec_user_id = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id'];
     287      $arg1       = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['arg1'];
     288      $arg2       = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['arg2'];
     289      if (empty($arg1)) $arg1 = 'NULL';
     290      if (empty($arg2)) $arg2 = 'NULL';
     291      if (empty($ec_user_id)) $ec_user_id = 'NULL';
     292      if ($_POST['ec_act1'] == 'toggle_forced') {
     293        $forced = (
     294          $ec_lists['ec_table'][$_POST['ec_entry_sel']]['forced'] == 'true'
     295        ) ? 'false' : 'true';
     296        $del_other = ($forced == 'true');
     297        $action     = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['action'];
     298      }
     299     
     300    if (
     301      $_POST['ec_act1'] == 'toggle_forced' or
     302      $_POST['ec_act1'] == 'modify_entry_submit'
     303    ) {
     304      $is_creation = false;
     305      break;
     306    }
    273307     
    274308      build_ec_duplicable_codes();
     
    276310       $ec_lists['duplicable_codes']['ids'])
    277311      ) return ec_end1('ec_entry_sel', 'ec_bad_argument5');
    278       $ec_code    = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['code'];
    279       $ec_user_id = $ec_lists['ec_table'][$_POST['ec_entry_sel']]['user_id'];
    280312     
    281313    break;
     
    283315  }
    284316 
    285   // Preparation of $arg1, $arg2 and $forced
    286   switch ($_POST['ec_input_action']) {
    287     // case 'home':  // Home : nothing to do : "arg"s are ''
    288     // case 'refused': $_POST['ec_sel_user'] unset, nothing to do
    289     case 'add_p': // Additional Page
    290       if (isset($_POST['ec_in_up_aps'])) $arg2 = $_POST['ec_in_up_aps'];
    291       else ec_end1('ec_in_up_aps', 'ec_bad_argument1');
    292     break;
    293     case 'cat':   // Category
    294     case 'img':   // Image
    295       if (isset($_POST['ec_in_up_cat'])) {
    296         $arg1 = $_POST['ec_in_up_cat'];
    297         if ($_POST['ec_input_action'] == 'img') {
    298           if (isset($_POST['ec_in_up_img'])) $arg2 = $_POST['ec_in_up_img'];
    299           else ec_end1('ec_in_up_img', 'ec_bad_argument1');
     317  if ($_POST['ec_act1'] != 'toggle_forced') {
     318    // Preparation of $arg1, $arg2
     319    switch ($_POST['ec_input_action']) {
     320      case 'add_p': // Additional Page
     321        if (isset($_POST['ec_in_up_aps'])) $arg2 = $_POST['ec_in_up_aps'];
     322        else ec_end1('ec_in_up_aps', 'ec_bad_argument1');
     323        $arg1 = 'NULL';
     324      break;
     325      case 'cat':   // Category
     326      case 'img':   // Image
     327        if (isset($_POST['ec_in_up_cat'])) {
     328          $arg1 = $_POST['ec_in_up_cat'];
     329          if ($_POST['ec_input_action'] == 'img') {
     330            if (isset($_POST['ec_in_up_img'])) $arg2 = $_POST['ec_in_up_img'];
     331            else ec_end1('ec_in_up_img', 'ec_bad_argument1');
     332          }
     333          else $arg2 = 'NULL';
    300334        }
    301       }
    302       else ec_end1('ec_in_up_cat', 'ec_bad_argument1');
    303     break;
    304     default: ec_end1('ec_input_action', 'ec_bad_argument1');
    305   }
    306  
    307   if (isset($_POST['ec_in_up_forced'])) {
    308     if ($_POST['ec_act1'] == 'duplicate_entry_submit')
    309      ec_end1('ec_in_up_forced', 'ec_bad_argument1');
    310     if (!$is_creation) {
    311       if (
    312         $t1 = mysql_fetch_row(pwg_query("
    313           SELECT `code`
    314           FROM `".EVNTCATS_TABLE."`
    315           WHERE `id` = '".$_POST['ec_entry_sel']."'
    316         ")) === false
    317       ) die('Code not found in DB ?!');
    318       $r = pwg_query("
    319         SELECT `id`
     335        else ec_end1('ec_in_up_cat', 'ec_bad_argument1');
     336      break;
     337      case 'home':    // Home : nothing to do : "arg"s are ''
     338      case 'refused': // $_POST['ec_sel_user'] unset, nothing to do
     339        $arg1 = 'NULL'; $arg2 = 'NULL';
     340      break;
     341      default: ec_end1('ec_input_action', 'ec_bad_argument1');
     342    }
     343   
     344    // Preparation of $forced
     345    $forced = (isset($_POST['ec_in_up_forced'])) ? 'true' : 'false';
     346    if ($_POST['ec_act1'] == 'duplicate_entry_submit' and $forced == 'true')
     347     return ec_end1('ec_in_up_forced', 'ec_bad_argument1');
     348   
     349    // User and eventually group creation, if needed
     350    if ($_POST['ec_act1'] != 'duplicate_entry_submit')
     351     if (isset($_POST['ec_sel_user']) and $_POST['ec_sel_user'] == 'new')
     352      if (!($ec_user_id = ec_create_user_OK())) return false;
     353  }
     354 
     355  // Now we have all infos : check that future entry doesn't exist already
     356  $arg1p = ($arg1 == 'NULL') ? 'IS NULL' : ' = '.$arg1;
     357  $arg2p = ($arg2 == 'NULL') ? 'IS NULL' : ' = '.$arg2;
     358  $ec_user_idp = ($ec_user_id == 'NULL') ? 'IS NULL' : ' = '.$ec_user_id;
     359  if (($t1 = mysql_fetch_row(pwg_query(// $q =
     360  "
     361    SELECT `id`
     362    FROM `".EVNTCATS_TABLE."`
     363    WHERE `code`    = '".$ec_code."'
     364      AND `user_id`    ".$ec_user_idp."
     365      AND `action`  = '".$action."'
     366      AND `arg1`       ".$arg1p."
     367      AND `arg2`       ".$arg2p."
     368      AND `forced`  = '".$forced."'
     369  "))) !== false) { // print("<pre>$arg1 $arg2<br>$q</pre>");
     370    $page['errors'][] = l10n('ec_entry_already_exists').$t1[0];
     371    return false;
     372  }
     373 
     374  // Delete other entries using the same code, if needed
     375  if ($del_other) {
     376    if ((
     377      $t1 = mysql_fetch_row(pwg_query("
     378        SELECT `code`
    320379        FROM `".EVNTCATS_TABLE."`
    321         WHERE `code` = '".$t1[0]."'
    322          AND `id` <> '".$_POST['ec_entry_sel']."'
    323       ");
    324       while ($t2 = mysql_fetch_row($r)) if (!ec_delete_entry_OK($t2[0]))
    325        return false;
    326     }
    327     $forced = 'true';
    328   }
    329   else $forced = 'false';
    330  
    331   // User and eventually group creation, if needed
    332   if ($_POST['ec_act1'] != 'duplicate_entry_submit')
    333    if ($_POST['ec_sel_user'] == 'new')
    334     if (!($ec_user_id = ec_create_user_OK())) return false;
    335  
    336   // Now we have all infos
     380        WHERE `id` = ".$_POST['ec_entry_sel']
     381      ))) === false
     382    ) die('Entry not found in DB ?!');
     383    $r = pwg_query("
     384      SELECT `id`
     385      FROM `".EVNTCATS_TABLE."`
     386      WHERE `code` = '".$t1[0]."'
     387       AND `id` <> ".$_POST['ec_entry_sel']
     388    );
     389    while ($t2 = mysql_fetch_row($r)) if (!ec_delete_entry_OK($t2[0]))
     390     return false;
     391  }
     392 
     393  $ec_debug[] = array(
     394    'del_other' => $del_other,
     395    'code' => $ec_code,
     396    'user_id' => $ec_user_id,
     397    'user_idp' => $ec_user_idp,
     398    'action' => $action,
     399    'arg1' => $arg1,
     400    'arg2' => $arg2,
     401    'arg1p' => $arg1p,
     402    'arg2p' => $arg2p,
     403    'forced' => $forced,
     404  );
     405 
     406  // Action !
     407  $ret = true;
    337408  if ($is_creation) {
    338409    if (
     
    346417        VALUES (
    347418          '".$ec_code."',
    348           '".$ec_user_id."',
     419           ".$ec_user_id.",
    349420          '".$action."',
    350           '".$arg1."', '".$arg2."', '".$forced."'
     421          ".$arg1.", ".$arg2.", '".$forced."'
    351422        );
    352423      ") === false
     
    356427       'MySQL error '.mysql_errno().', "'.mysql_error().'"'
    357428      ;
    358       return false;
     429      $ret = false;
    359430    }
    360431    else {
     
    363434      $page['infos'][] =
    364435       l10n('ec_entry_create_OK').mysql_insert_id().' : '.
    365        $_POST['ec_in_up_code'].' => '.
     436       $ec_code.' => '.
    366437       $ec_lists['user_ids'][$ec_user_id].$forced
    367438      ;
     439      return true;
    368440    }
    369441  }
     
    373445        UPDATE `".EVNTCATS_TABLE."`
    374446        SET
    375           `user_id` = '".$ec_user_id."',
     447          `user_id` =  ".$ec_user_id.",
    376448          `action`  = '".$action."',
    377           `arg1`    = '".$arg1."',
    378           `arg2`    = '".$arg2."',
     449          `arg1`    =  ".$arg1.",
     450          `arg2`    =  ".$arg2.",
    379451          `forced`  = '".$forced."'
    380452        WHERE `id`  = '".$_POST['ec_entry_sel']."'
     
    385457       'MySQL error '.mysql_errno().', "'.mysql_error().'"'
    386458      ;
    387       return false;
    388     }
    389     else {
    390       $page['infos'][] = l10n('ec_entry_modify_OK').$_POST['ec_entry_sel'];
    391       build_ec_lists();
    392     }
    393   }
    394   return true;
    395 }
    396 
    397 /*
    398  * ec_toggle_forced_entry()
    399  * Toggles the 'forced' property of an entry, provided it complies to the
    400  * rules.
    401  *
    402  * @param
    403  *   no param
    404  * @return
    405  *   no return value
    406  */
    407 function ec_toggle_forced_entry() {
    408   global $page;
    409   $page['errors'][] = 'ec_toggle_forced_entry';
     459      $ret = false;
     460    }
     461    else $page['infos'][] = l10n('ec_entry_modify_OK').$_POST['ec_entry_sel'];
     462  }
     463  build_ec_lists();
     464  return $ret;
    410465}
    411466
  • extensions/event_cats/include/evntcats_main_funcs.inc.php

    r4218 r4219  
    6969    FROM `".IMAGE_CATEGORY_TABLE."`
    7070    WHERE `category_id` = ".$cat."
    71      AND `image_id` = ".$img."`
    72   ")) !== false);
     71     AND `image_id` = ".$img
     72  )) !== false);
    7373}
    7474
Note: See TracChangeset for help on using the changeset viewer.