1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | global $template; |
---|
6 | |
---|
7 | // Add or modify new criteria |
---|
8 | // if previous page is "config" ==> id_concours=0. After submit, redirect to config page |
---|
9 | // if previous page is add_concours with action modify_crit and id_concours !=0, redirect to add_concours page with correct params. |
---|
10 | |
---|
11 | // action = modify/add/edit |
---|
12 | |
---|
13 | $id_concours = (isset($_GET['id_concours']) ? $_GET['id_concours'] : 0); |
---|
14 | |
---|
15 | $concours = new Concours($id_concours); |
---|
16 | |
---|
17 | if (!isset($_GET['action'])) |
---|
18 | $_GET['action'] = "edit"; |
---|
19 | |
---|
20 | |
---|
21 | if (isset($_POST['submit'])) // validation |
---|
22 | { |
---|
23 | $datas = array(); |
---|
24 | |
---|
25 | $datas['id'] = isset($_GET['id']) ? $_GET['id'] : null; |
---|
26 | $datas['name'] = $_POST['criteria_name']; |
---|
27 | $datas['descr'] = $_POST['criteria_lib']; |
---|
28 | $datas['min_value'] = $_POST['criteria_min']; |
---|
29 | $datas['max_value'] = $_POST['criteria_max']; |
---|
30 | $datas['ponderation'] = $_POST['criteria_pond']; |
---|
31 | $datas['uppercriteria'] = isset($_GET['upcriteria']) ? $_GET['upcriteria'] : false; |
---|
32 | // if action = add |
---|
33 | if ($_GET['action'] == "add") |
---|
34 | { |
---|
35 | $concours->add_criteria($datas); |
---|
36 | } |
---|
37 | // if action = modify |
---|
38 | elseif ($_GET['action'] == "modify" ) |
---|
39 | { |
---|
40 | $concours->update_criteria($datas); |
---|
41 | } |
---|
42 | |
---|
43 | if ($id_concours == 0) |
---|
44 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&tab=config'); |
---|
45 | else |
---|
46 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&tab=add_concours&action=modify_crit&concours=' . $id_concours); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | switch ($_GET['action']) |
---|
51 | { |
---|
52 | |
---|
53 | case "delete" : |
---|
54 | if (!isset($_GET['id'])) |
---|
55 | die ("Wrong parameters..."); |
---|
56 | else |
---|
57 | { |
---|
58 | if ($concours->debug) echo "ID=".$_GET['id']; |
---|
59 | $concours->delete_criteria_by_id($_GET['id']); |
---|
60 | |
---|
61 | if ($id_concours == 0) |
---|
62 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&tab=config'); |
---|
63 | else |
---|
64 | redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin§ion=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php&tab=add_concours&action=modify_crit&concours=' . $id_concours); |
---|
65 | |
---|
66 | } |
---|
67 | break; |
---|
68 | |
---|
69 | case "modify" : |
---|
70 | if (!isset($_GET['id'])) |
---|
71 | die ("Wrong parameters..."); |
---|
72 | else |
---|
73 | { |
---|
74 | $criteria = $concours->get_criteria_by_id($_GET['id']); |
---|
75 | if (!$criteria == array()) // Not found |
---|
76 | { |
---|
77 | $template->assign( array( |
---|
78 | 'criteria_id' => $criteria['criteria_id'], // id du critere |
---|
79 | 'criteria_name' => $criteria['name'], // id du critere |
---|
80 | 'criteria_lib' => $criteria['descr'], //.'(min='$criteria['min_value'].';max='.$criteria['min_value'].')', // libelle du critrer |
---|
81 | 'criteria_min' => $criteria['min_value'], // min |
---|
82 | 'criteria_max' => $criteria['max_value'], // max |
---|
83 | 'criteria_pond' => $criteria['ponderation'], // ponderation |
---|
84 | 'action' => $_GET['action'] |
---|
85 | )); |
---|
86 | |
---|
87 | } |
---|
88 | |
---|
89 | } |
---|
90 | break; |
---|
91 | |
---|
92 | case "add" : |
---|
93 | $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id |
---|
94 | FROM ' . CONCOURS_DETAIL_TABLE . ' ;'; |
---|
95 | list($next_element_id) = mysql_fetch_array(pwg_query($query)); |
---|
96 | $query = 'SELECT IF(MAX(criteria_id)+1 IS NULL, 1, MAX(criteria_id)+1) AS next_criteria_id |
---|
97 | FROM ' . CONCOURS_DETAIL_TABLE . ' |
---|
98 | WHERE id_concours = '.$concours->concours_id . ' ;'; |
---|
99 | list($next_criteria_id) = mysql_fetch_array(pwg_query($query)); |
---|
100 | |
---|
101 | $template->assign( array( |
---|
102 | 'criteria_id' => $next_criteria_id, // id du critere |
---|
103 | 'action' => $_GET['action'] |
---|
104 | )); |
---|
105 | break; |
---|
106 | default : |
---|
107 | break; |
---|
108 | } |
---|
109 | |
---|
110 | $template->assign( array('EDIT'=>(isset($_GET['edit']) ? true : false))); |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/criteria.tpl'); |
---|
115 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
116 | |
---|
117 | ?> |
---|