function notice($text, $action = 'add') { static $notices; if ($action == 'add') { $notices[] = $text; } elseif ($action == 'get') { if (count($notices) > 0) { $output = '<div class="notices">' . array_to_list($notices) . '</div>'; unset($notices); return $output; } } }
function process($values) { // Since we're using 'id' for the unique id input, set the actual unique id column value. $values[$this->id_column] = $values['id']; $errors = $this->validate($values); // If there's any errors, add a notice if (count($errors) > 0) { notice(array_to_list($errors)); return $this->form($values['id']); // If no errors, go ahead and add the entry. } else { $clean_columns[] = $this->id_column; foreach ($this->add_edit_columns as $column_name => $column_options) { $clean_columns[] = $column_name; } foreach ($clean_columns as $column) { $clean_values[$column] = trim(mysql_real_escape_string($values[$column])); } // Remove the unique ID column from values and columns so we can use implode() later. $update_values = $clean_values; unset($update_values[$this->id_column]); $update_columns = $clean_columns; // We can do this because we know we added the id column first. unset($update_columns[0]); //die(var_dump($values)); // Do an insert if we're adding. if ($clean_values[$this->id_column] == '') { $add_query = "'" . implode("','", $update_values) . "'"; $column_names = implode(',', $update_columns); $sql = "INSERT INTO " . $this->table . " (" . $column_names . ") VALUES (" . $add_query . ")"; // Do an update if we're editing. } else { foreach ($update_columns as $column) { $update_query_array[] = " " . $column . " = '" . $clean_values[$column] . "' "; } $update_query = implode(',', $update_query_array); $sql = "\n UPDATE " . $this->table . "\n SET " . $update_query . "\n WHERE " . $this->id_column . " = '" . $clean_values[$this->id_column] . "'"; } $result = mysql_query($sql); notice($sql); // $result will return TRUE if it worked. Otherwise, we should show an error to troubleshoot. if ($result) { notice($clean_values[$this->id_column] == '' ? 'The ' . $this->item_name . ' was added.' : 'The ' . $this->item_name . ' was updated'); } else { // If something happened, let's show an error. notice(mysql_error()); } } }
function admin_users_add_edit_form_process($values, $action) { $errors = admin_users_add_edit_form_validate($values, $action); // If there's any errors, add a notice if (count($errors) > 0) { notice(array_to_list($errors)); return admin_users_add_edit_form($values['uid']); // If no errors, go ahead and add the person. } else { // Changed name of variable here. $input_names = array('uid', 'username', 'password'); foreach ($input_names as $input_name) { $clean_values[$input_name] = trim(mysql_real_escape_string($values[$input_name])); } // Do an insert if we're adding. if ($clean_values['uid'] == '') { $add_values = $clean_values; unset($add_values['uid']); $add_query = "'" . implode("','", $add_values) . "'"; $sql = "INSERT INTO users (username, password) VALUES (" . $add_query . ")"; // Do an update if we're editing. } else { $sql = "\n UPDATE users\n SET username = '******'username'] . "',\n password = '******'password'] . "'\n WHERE uid = '" . $clean_values['uid'] . "'"; } $result = mysql_query($sql); notice($sql); // $result will return TRUE if it worked. Otherwise, we should show an error to troubleshoot. if ($result) { notice($clean_values['uid'] == '' ? 'The user was added.' : 'The user was updated'); } else { // If something happened, let's show an error. notice(mysql_error()); } } }
?> </td>--> <!-- <td> <?php echo $user['designation']; ?> </td>--> <td> <?php echo $user['email']; ?> </td> <!-- <td> <?php echo $user['address']; ?> </td>--> <td> <?php array_to_list(acl_get_user_roles($user['username'])); ?> </td> <td> <?php echo $user['status']; ?> </td> <td> <?php echo TwoStepColumnDecorator::decorate($user['config']); ?> </td> <td> <a href="<?php get_url('admin', 'edit_user', null, array('uid' => $user['username'])); ?> " class="btn btn-info btn-mini"><i class="icon-edit icon-white"></i> <?php
echo "<li>" . $fruits[$i] . "</li>\n"; } echo "</ul>\n"; echo '<h1>Avec une boucle while()</h1>'; $i = 0; echo "<ul>\n"; while ($i < 3) { echo "<li>" . $fruits[$i] . "</li>\n"; $i++; } echo "</ul>\n"; //Pour l'affichage avec la boucle foreach on peut réutiliser //la fonction array_to_list vu en TD 2 include '../../TD/2/array_to.php'; echo '<h1>Avec une boucle foreach()</h1>'; echo array_to_list($fruits); /*Pour l'affichage avec la boucle foreach on peut réutiliser la fonction arrayEnTableHTML vu en TD 3 qui se trouve dans le fichier ShowForm.php*/ include '../../TD/3/ShowForm.php'; echo '<h1>Calories</h1>'; echo "<h2>Tri par valeurs de calories croissantes</h2>\n"; asort($fruits2); echo arrayEnTableHTML($fruits2, "Table triée par valeur"); echo '<h2>Tri par noms de fruits</h2>'; ksort($fruits2); echo arrayEnTableHTML($fruits2, "Table triée par clef"); echo '</body></html>'; ?>