*/ require_once 'config.php'; function askConfirm($id, $jobs, $db){ /* gets the jobs data, in order to ask for delete confirmation */ $result = $jobs->get($id); $new = $db->getObject($result); return ' '.TXT_JOBS_DEL_CONF.'
'.$new->title.'
'.$new->name.'

'.TXT_YES.' - '.TXT_NO.'
'; } function getFormJobs($id='', $title='', $name='', $department='', $contract='', $author='', $reports_to='', $contacts_in='', $contacts_out='', $jobs='', $rules='', $action='', $active=''){ //if we are adding // if no id then we need to add the jobs ||| Est-il important d'utiliser array() pour initialiser un tableau, ou peu-on le faire juste avec array[x] = ''? $i=1; echo $rules; if ($rules!='') { echo 'cool'; $rules = unserialize($rules); if (substr($action, 0, 3)=='add'){ $rules[0]++; $rules[$rules[0]]=''; echo $rules[0]; } else { $rules[0]--; } if ($id=='') $action = 'addJobs'; else $action = 'modJobs'; //rules is only set on 'addField' action ---> this is an addField query } elseif ($id=='') { $rules = array(1, ''); $action = 'addJobs'; //otherwise this is a modify request } else { $rules[0] = $jobs->countSpecs($id, 'rule'); $result = $jobs->getSpecs($id, 'rule'); for ($i=1;$i<=$rules[0];$i++){ $new=mysql_fetch_array($result); $rules[$i] = $new['text']; // 2 is bound to the 'text' row } $action = 'modJobs'; } $form = '
'; for ($i=1;$i<=$rules[0];$i++){ $form .= ''; } $form .= '
'.TXT_FORM_TITLE.'
'.TXT_FORM_NAME.'
'.TXT_FORM_DEPARTMENT.'
'.TXT_FORM_CONTRACT.'
'.TXT_FORM_AUTHOR.'
'.TXT_FORM_REPORTS.'
'.TXT_FORM_CONTACTS_IN.'
'.TXT_FORM_CONTACTS_OUT.'
'.TXT_FORM_RULES.' '.$i.'
 
'; return $form; } function editJobs($title, $name, $department, $contract, $author, $reports_to, $contacts_in, $contacts_out, $rules='', $jobs, $db, $mode='add', $id='', $modField=false){ //If adding a field, skip the testing sequence if (!$modField) if (!$jobs->testAllFields($title, $name, $department, $contract, $author, $reports_to, $contacts_in, $contacts_out, $rules)){ return ERR_FIELD_EMPTY; } $rules = (unserialize($rules)); if ($mode=='add') { if (!$jobs->add($title, $name, $department, $contract, $author, $reports_to, $contacts_in, $contacts_out)) return ERR_MSG_ADD_JOBS; //FAIRE ATTENTION A CE QUE RENVOIE add (A TESTER AVEC ATTENTION) for ($i=1;$i<=$rules[0];$i++){ if (!$jobs->addSpecs($rules[$i], 'rule', $i)) return ERR_MSG_ADD_JOBS; } return TXT_MSG_JOB_ADDED; } else { if (!$jobs->mod($id, $title, $name, $department, $contract, $author, $reports_to, $contacts_in, $contacts_out)) return ERR_MSG_MOD_JOBS; for ($i=1;$i<=$rules[0];$i++){ if (!$jobs->updateSpecs($rules[$i], 'rule', $i, $id)) return ERR_MSG_MOD_JOBS; } return TXT_MSG_JOB_MOD; } } function updateImg($jobs, $db, &$msgError, $id=''){ //get the id of the last jobs if needed if ($id==''){ $result = $jobs->getLast(); $new = $db->getObject($result); $id = $new->id; } /* if no upload error */ if ($_FILES["image"]["error"]==UPLOAD_ERR_OK) { if (!stristr($_FILES["image"]["name"], '.jpg')) {$msgError = ERR_MSG_IMG_NOT_JPG; return false;} $name = 'imgJobs_'.$id.'.jpg'; move_uploaded_file($name, IMG_JOBS_PATH.$name); createImage(IMG_JOBS_PATH.$name, IMG_JOBS_SIZE_SMALL, "_small"); createImage(IMG_JOBS_PATH.$name, IMG_JOBS_SIZE_NORMAL, "_normal"); return true; } return false; } function getLstJobs($db, $jobs){ $lstJobs = ''; $allJobs = $jobs->getAll(); $lstJobs .= ''; while ($new = $db->getObject($allJobs)){ $lstJobs .= ''; if ($new->active=='y'){ $lstJobs .= ''; } $lstJobs .= '
'; } else{ $lstJobs .= ''; } $lstJobs .= ''.substr($new->title, 0, TITLE_MAX_CHARS).''; $lstJobs .= ''.date('d/m/Y '.TXT_ON_TIME.' H:i:s', $new->date).''; $lstJobs .= ''; $lstJobs .= ''; $lstJobs .= '
'; return $lstJobs; } $htmlToShow = ''; /* if there is a task to do */ if (isset ($_REQUEST['addField'])){ $_REQUEST['action'] = 'addField'; $modField = true; } if (isset($_REQUEST['rules'])){ $rules = array($_REQUEST['rules']); } for ($i=1;isset($_REQUEST['rule'.$i.'']);$i++){ $rules[$i] = $_REQUEST['rule'.$i.'']; } if (isset($_REQUEST['rules'])) $rules = serialize($rules); if (isset($_REQUEST['action'])){ switch ($_REQUEST['action']){ case 'getFormJobs': $htmlToShow = getFormJobs(); break; case 'getModForm': $result = $jobs->get($_REQUEST['id']); $new = $db->getObject($result); $htmlToShow = getFormJobs($new->id, $new->title, $new->name, $new->department, $new->contract, $new->author, $new->reports_to, $new->contacts_in, $new->contacts_out, $jobs); break; case 'addJobs': $htmlToShow = editJobs($_REQUEST['title'], $_REQUEST['name'], $_REQUEST['department'], $_REQUEST['contract'], $_REQUEST['author'], $_REQUEST['reports_to'], $_REQUEST['contacts_in'], $_REQUEST['contacts_out'], $rules, $jobs, $db, 'add'); break; case 'modJobs': $htmlToShow = editJobs($_REQUEST['title'], $_REQUEST['name'], $_REQUEST['department'], $_REQUEST['contract'], $_REQUEST['author'], $_REQUEST['reports_to'], $_REQUEST['contacts_in'], $_REQUEST['contacts_out'], $rules, $jobs, $db, 'mod', $_REQUEST['id']); break; case 'callDelMsg': $htmlToShow = askConfirm($_REQUEST['id'], $jobs, $db); break; case 'delJobs': $jobs->del($_REQUEST['id']); $htmlToShow = TXT_MSG_JOB_DELETED; break; case 'addField': $htmlToShow = getFormJobs('', $_REQUEST['title'], $_REQUEST['name'], $_REQUEST['department'], $_REQUEST['contract'], $_REQUEST['author'], $_REQUEST['reports_to'], $_REQUEST['contacts_in'], $_REQUEST['contacts_out'], $jobs, $rules, $_REQUEST['action']); break; default: break; } } // The list of all jobs $lstJobs = getLstJobs($db, $jobs); $htmlToShow .= '

'; echo $htmlToShow; ?>