= 0"); $row = $stH->fetch(PDO::FETCH_NUM); $stH = null; $nrCats = $row[0]; function showCategories($bare) { //bare: no edit/add buttons global $ax; echo "
{$ax['cat_list']}\n"; $stH = stPrep("SELECT * FROM `categories` WHERE `status` >= 0 ORDER BY `sequence`"); stExec($stH,null); $rows = $stH->fetchAll(PDO::FETCH_ASSOC); echo ""; if (!$bare) { echo ""; } echo "\n"; foreach ($rows as $cat) { switch ($cat['repeat']) { case 0: $repeat = ''; break; case 1: $repeat = $ax['cat_every_day']; break; case 2: $repeat = $ax['cat_every_week']; break; case 3: $repeat = $ax['cat_every_month']; break; case 4: $repeat = $ax['cat_every_year']; } $style = ($cat['color'] ? "color:{$cat['color']};" : '').($cat['bgColor'] ? "background-color:{$cat['bgColor']};" : ''); $style = $style ? " style='{$style}'" : ''; echo "\n{$cat['name']}'; if (!$bare) { echo "" : ''; echo "\n"; } echo "\n"; } echo "
 {$ax['cat_nr']}  {$ax['id']} {$ax['cat_cat_name']}{$ax['cat_symbol']}{$ax['cat_repeat']}{$ax['cat_overlap']}{$ax['cat_duration']}{$ax['cat_need_approval']}{$ax['cat_day_color']}{$ax['cat_check_mark']}{$ax['cat_subcats']}
{$cat['sequence']}{$cat['ID']}{$cat['symbol']}{$repeat} ".($cat['noverlap'] < 1 ? $ax['yes'] : $ax['no'].' ('.$cat['olapGap'].')')." ".($cat['defSlot'] > 0 ? substr('0'.intval($cat['defSlot'] / 60),-2).':'.substr('0'.($cat['defSlot'] % 60),-2).($cat['fixSlot'] > 0 ? ' !' : '') : '')." ".($cat['approve'] < 1 ? $ax['no'] : $ax['yes'])." ".($cat['dayColor'] < 1 ? $ax['no'] : $ax['yes'])." ".($cat['checkBx'] ? $cat['checkMk'].': "'.$cat['checkLb'].'"' : $ax['no'])." ".(($cat['subName1'] or $cat['subName2'] or $cat['subName3'] or $cat['subName4']) ? $ax['yes'] : $ax['no']).'"; echo ($cat['ID'] > 1) ? "
\n"; echo "
\n"; if (!$bare) { echo "\n"; echo "   \n"; } echo "

\n"; } function sortCategories() { $stH = dbQuery("SELECT `ID` FROM `categories` WHERE `status` >= 0 ORDER BY CASE WHEN `ID` < 2 THEN `ID` ELSE `name` END"); $rowArray = $stH->fetchAll(PDO::FETCH_ASSOC); $stH = null; $stH = stPrep("UPDATE `categories` SET `sequence` = ? WHERE `ID` = ?"); $count = 0; foreach ($rowArray as $row) { stExec($stH,array(++$count,$row['ID'])); } } function editCategory($cat) { global $ax, $mode, $nrCats, $lcI; echo "
\n"; echo "
"; if ($mode == 'edit') { //edit $stH = stPrep("SELECT * FROM `categories` WHERE `ID` = ? LIMIT 1"); stExec($stH,array($cat['id'])); $row = $stH->fetch(PDO::FETCH_ASSOC); $stH = null; if ($row and !isset($_POST['cname'])) { $cat['name'] = $row['name']; $cat['color'] = $row['color'] ? $row['color'] : '#303030'; $cat['bgrnd'] = $row['bgColor'] ? $row['bgColor'] : '#FFFFFF'; $cat['symbl'] = $row['symbol']; $cat['sqnce'] = $row['sequence']; $cat['rpeat'] = $row['repeat']; $cat['nolap'] = $row['noverlap']; $cat['olGap'] = $row['olapGap']; $cat['olErr'] = $row['olErrMsg']; $cat['tsHrs'] = intval($row['defSlot'] / 60); $cat['tsMin'] = $row['defSlot'] % 60; $cat['tsFix'] = $row['fixSlot']; $cat['appro'] = $row['approve']; $cat['daybg'] = $row['dayColor']; $cat['chBox'] = $row['checkBx']; $cat['chLab'] = $row['checkLb']; $cat['chMrk'] = $row['checkMk']; $cat['subN1'] = $row['subName1']; $cat['subC1'] = $row['subColor1'] ? $row['subColor1'] : '#303030'; $cat['subB1'] = $row['subBgrnd1'] ? $row['subBgrnd1'] : '#FFFFFF'; $cat['subN2'] = $row['subName2']; $cat['subC2'] = $row['subColor2'] ? $row['subColor2'] : '#303030'; $cat['subB2'] = $row['subBgrnd2'] ? $row['subBgrnd2'] : '#FFFFFF'; $cat['subN3'] = $row['subName3']; $cat['subC3'] = $row['subColor3'] ? $row['subColor3'] : '#303030'; $cat['subB3'] = $row['subBgrnd3'] ? $row['subBgrnd3'] : '#FFFFFF'; $cat['subN4'] = $row['subName4']; $cat['subC4'] = $row['subColor4'] ? $row['subColor4'] : '#303030'; $cat['subB4'] = $row['subBgrnd4'] ? $row['subBgrnd4'] : '#FFFFFF'; preg_match('~(.+)\s*\[(.*)\]~',$row['urlLink'],$matches); $cat['urlLk'] = !empty($matches[1]) ? $matches[1] : ''; $cat['urlNm'] = !empty($matches[2]) ? $matches[2] : '';; } echo "{$ax['cat_edit_cat']}\n"; } else { //add echo "{$ax['cat_add_new']}\n"; $cat['sqnce'] = $nrCats + 1; } $style = ($cat['color'] ? "color:{$cat['color']};" : "").($cat['bgrnd'] ? "background-color:{$cat['bgrnd']};" : ""); $style = $style ? " style='{$style}'" : ''; $selected = array_fill(0,5,''); $selected[$cat['rpeat']] = ' selected'; echo "\n"; if ($mode != 'add') { echo "\n"; } echo "\n"; for ($i = 1; $i <= 4; $i++) { $style = ($cat['subC'.$i] ? "color:{$cat['subC'.$i]};" : "").($cat['subB'.$i] ? "background-color:{$cat['subB'.$i]};" : ""); $style = $style ? " style='{$style}'" : ''; echo "\n"; } echo "
{$ax['id']}: {$cat['id']}
{$ax['cat_cat_name']}:
{$ax['cat_cat_color']}:{$ax['cat_text']}:   {$ax['cat_background']}:
{$ax['cat_symbol_repms']}: ({$ax['cat_symbol_eg']})
{$ax['cat_seq_in_menu']}:
{$ax['cat_repeat']}:
{$ax['cat_no_overlap']} *:: " : ' > ')."  : " : ' > ')."  {$ax['cat_gap']}: (0-720 {$ax['minutes']})
{$ax['cat_ol_error_text']}:
{$ax['cat_event_duration']} (0: {$ax['none']}): {$ax['hours']}   {$ax['minutes']}     
: " : ' > ')."
: " : ' > ')."
: " : ' > ')."
:   {$ax['cat_label']}:   {$ax['cat_mark']}:
{$ax['cat_matrix_url_link']}:{$ax['cat_name']}:   {$ax['cat_url']}:
{$ax['cat_subcats_opt']}:
{$i} - {$ax['cat_name']}:  {$ax['cat_text']}:   {$ax['cat_background']}:
* {$ax['cat_no_ol_note']}
\n"; if ($mode == 'add') { echo ""; } else { echo ""; } echo "   



\n"; } function validateCat(&$cat) { //add category global $ax, $nrCats, $rxCalURL; $msg = ''; //init do { if (!$cat['name']) { $msg = $ax['cat_name_missing']; break; } if (!ctype_digit($cat['olGap']) or $cat['olGap'] < 0 or $cat['olGap'] > 720) { $msg = $ax['cat_olgap_invalid']; break; } if (!ctype_digit($cat['tsHrs']) or $cat['tsHrs'] < 0 or !ctype_digit($cat['tsMin']) or $cat['tsMin'] > 59 or $cat['tsMin'] < 0) { $msg = $ax['cat_duration_invalid']; break; } if ($cat['chBox'] and (!$cat['chLab'] or !$cat['chMrk'])) { $msg = $ax['cat_mark_label_missing']; break; } if (!ctype_digit($cat['sqnce']) or $cat['sqnce'] == 0) { $cat['sqnce'] = 1; } elseif ($cat['sqnce'] > $nrCats) { $cat['sqnce'] = $nrCats + 1; } if ($cat['nolap'] and !$cat['olErr']) { $msg = $ax['cat_no_ol_error_msg']; break; } if (($cat['urlNm'] and !$cat['urlLk']) or ($cat['urlLk'] and !preg_match($rxCalURL, $cat['urlLk']))) { $msg = $ax['cat_invalid_url']; break; } $cat['urlNm'] = str_replace(array('[',']'),'',$cat['urlNm']); if ($cat['urlLk'] and empty($cat['urlNm'])) { $msg = $ax['cat_no_url_name']; break; } $cat['urlLN'] = $cat['urlLk'] ? "{$cat['urlLk']}[{$cat['urlNm']}]" : ''; } while (false); return $msg; } function addCat(&$cat) { //add category global $ax, $mode, $nrCats; do { //validate form fields if ($msg = validateCat($cat)) { break; } //renumber sequence $stH = stPrep("SELECT `ID` FROM `categories` WHERE `status` >= 0 AND `sequence` >= ? ORDER BY `sequence`"); stExec($stH,array($cat['sqnce'])); $rowArray = $stH->fetchAll(PDO::FETCH_ASSOC); $stH = null; $stH = stPrep("UPDATE `categories` SET `sequence` = ? WHERE `ID` = ?"); $count = $cat['sqnce']; foreach ($rowArray as $row) { stExec($stH,array(++$count,$row['ID'])); } //add new category $stH = stPrep("INSERT INTO `categories` (`name`,`symbol`,`sequence`,`repeat`,`noverlap`,`olapGap`,`olErrMsg`,`defSlot`,`fixSlot`,`approve`,`dayColor`,`color`,`bgColor`,`checkBx`,`checkLb`,`checkMk`,`subName1`,`subColor1`,`subBgrnd1`,`subName2`,`subColor2`,`subBgrnd2`,`subName3`,`subColor3`,`subBgrnd3`,`subName4`,`subColor4`,`subBgrnd4`,`urlLink`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); stExec($stH,array($cat['name'],$cat['symbl'],$cat['sqnce'],$cat['rpeat'],$cat['nolap'],$cat['olGap'],$cat['olErr'],(($cat['tsHrs'] * 60) + $cat['tsMin']),$cat['tsFix'],$cat['appro'],$cat['daybg'],$cat['color'],$cat['bgrnd'],$cat['chBox'],$cat['chLab'],$cat['chMrk'],$cat['subN1'],$cat['subC1'],$cat['subB1'],$cat['subN2'],$cat['subC2'],$cat['subB2'],$cat['subN3'],$cat['subC3'],$cat['subB3'],$cat['subN4'],$cat['subC4'],$cat['subB4'],$cat['urlLN'])); $count = $stH->rowCount(); if (!$count) { $msg = "Database Error: {$ax['cat_not_added']}"; break; } $msg = $ax['cat_added']; $mode = ''; } while (false); return $msg; } function updateCat(&$cat) { //update category global $ax, $mode, $nrCats; do { //validate form fields if ($msg = validateCat($cat)) { break; } //update $stH = stPrep("UPDATE `categories` SET `name`=?,`symbol`=?,`sequence`=?,`repeat`=?,`noverlap`=?,`olapGap`=?,`olErrMsg`=?,`defSlot`=?,`fixSlot`=?,`approve`=?,`dayColor`=?,`color`=?,`bgColor`=?,`checkBx`=?,`checkLb`=?,`checkMk`=?,`subName1`=?,`subColor1`=?,`subBgrnd1`=?,`subName2`=?,`subColor2`=?,`subBgrnd2`=?,`subName3`=?,`subColor3`=?,`subBgrnd3`=?,`subName4`=?,`subColor4`=?,`subBgrnd4`=?,`urlLink`=? WHERE `ID`=?"); stExec($stH,array($cat['name'],$cat['symbl'],$cat['sqnce'],$cat['rpeat'],$cat['nolap'],$cat['olGap'],$cat['olErr'],(($cat['tsHrs'] * 60) + $cat['tsMin']),$cat['tsFix'],$cat['appro'],$cat['daybg'],$cat['color'],$cat['bgrnd'],$cat['chBox'],$cat['chLab'],$cat['chMrk'],$cat['subN1'],$cat['subC1'],$cat['subB1'],$cat['subN2'],$cat['subC2'],$cat['subB2'],$cat['subN3'],$cat['subC3'],$cat['subB3'],$cat['subN4'],$cat['subC4'],$cat['subB4'],$cat['urlLN'],$cat['id'])); $count = $stH->rowCount(); if (!$count) { $msg = "Database Error: {$ax['cat_not_updated']}"; break; } //renumber sequence $stH = dbQuery("SELECT `ID` FROM `categories` WHERE `status` >= 0 ORDER BY `sequence`"); $rowArray = $stH->fetchAll(PDO::FETCH_ASSOC); $stH = null; $stH = stPrep("UPDATE `categories` SET `sequence` = ? WHERE `ID` = ?"); $count = 1; foreach ($rowArray as $row) { if ($row['ID'] != $cat['id']) { if ($count == $cat['sqnce']) { $count++; } stExec($stH,array($count++,$row['ID'])); } } $msg = $ax['cat_updated']; $mode = ''; } while (false); return $msg; } function deleteCat($cat) { //delete category global $ax; $stH = stPrep("UPDATE `categories` SET `sequence` = 0, `status` = -1 WHERE `ID` = ?"); stExec($stH,array($cat['id'])); $count = $stH->rowCount(); if (!$count) { $msg = "Database Error: {$ax['cat_not_deleted']}"; } else { $msg = $ax['cat_deleted']; //renumber sequence $stH = dbQuery("SELECT `ID` FROM `categories` WHERE `status` >= 0 ORDER BY `sequence`"); $rowArray = $stH->fetchAll(PDO::FETCH_ASSOC); $stH = null; $stH = stPrep("UPDATE `categories` SET `sequence` = ? WHERE `ID` = ?"); $count = 1; foreach ($rowArray as $row) { stExec($stH,array($count++,$row['ID'])); } } return $msg; } //Control logic if ($usr['privs'] >= 4) { //manager or admin $msg = ''; if (isset($_POST['addExe'])) { $msg = addCat($cat); } elseif (isset($_POST['updExe'])) { $msg = updateCat($cat); } elseif (isset($_POST['delExe'])) { $msg = deleteCat($cat); } echo "

{$msg}

\n"; if ($mode == 'sort') { sortCategories(); //sort on name } if (($mode != 'add' and $mode != 'edit') or isset($_POST['back'])) { showCategories(false); //no add / no edit } else { editCategory($cat); //add or edit showCategories(true); } echo "
\n
\n"; } else { echo "

{$ax['no_way']}

\n"; } ?>