YaWK  24.1
Yet another WebKit
settings-assets.php
Go to the documentation of this file.
1 <?php
2 use YAWK\alert;
3 use YAWK\backend;
4 use YAWK\db;
5 use YAWK\language;
6 /** @var $db db */
7 /** @var $lang language */
8 
9 // DELETE ASSET
10 if (isset($_GET['delete']) && ($_GET['delete'] == 1))
11 { // check if ID is set
12  if (isset($_GET['id']) && (!empty($_GET['id'])))
13  { // delte asset from db
14  if ($db->query("DELETE from {assets_types} WHERE id = $_GET[id]"))
15  { // success, throw msg
16  alert::draw("success", "$lang[SUCCESS]", "$lang[ASSET_DEL_OK]", "", "800");
17  }
18  else
19  { // failed to delete, throw error msg
20  alert::draw("danger", "$lang[ERROR]", "$lang[ASSET_DEL_FAILED]", "", "2600");
21  }
22  }
23 }
24 // ENABLE / DISABLE ASSET
25 if (isset($_GET['toggle']) && $_GET['toggle'] == 1)
26 {
27  // prepare user data
28  $id = $db->quote($_GET['id']);
29  $published = $db->quote($_GET['published']);
30 
31  // toggle publish state
32  if ($published == 1)
33  { $published = 0; }
34  else if ($published == 0)
35  { $published = 1; }
36 
37  // add asset to db
38  if ($db->query(("UPDATE {assets_types}
39  SET published = '" . $published . "'
40  WHERE id = '" . $id . "'")))
41  { // all good, throw success msg
42  alert::draw("success", "$lang[SUCCESS]", "$lang[ASSET_TOGGLE_OK]", "", "800");
43  }
44  else
45  { // failed to add new asset - throw error msg
46  alert::draw("danger", "$lang[ERROR]", "$lang[ASSET_TOGGLE_FAILED]", "", "2600");
47  }
48 }
49 
50 // POST DATA SENT
51 if (isset($_POST) && (!empty($_POST)))
52 {
53  // ADD NEW ASSET
54  if (isset($_GET['newAsset']) && $_GET['newAsset'] == true)
55  {
56  // prepare user data
57  $assetType = $db->quote($_POST['assetType']);
58  $assetName = $db->quote($_POST['assetName']);
59  $property = $db->quote($_POST['assetName']);
60  $internal = $db->quote($_POST['internal']);
61  $url1 = $db->quote($_POST['url1']);
62  $url2 = $db->quote($_POST['url2']);
63  $url3 = $db->quote($_POST['url3']);
64 
65  $row = $db->query("SELECT MAX(sortation) FROM {assets_types}");
66  $res = mysqli_fetch_row($row);
67  if (isset($res[0])){
68  $sortation = $res[0];
69  }
70  else {
71  $sortation = 0;
72  }
73 
74  // add asset to db
75  if ($db->query("INSERT INTO {assets_types} (type, sortation, asset, property, internal, url1, url2, url3)
76  VALUES ('".$assetType."', '".$sortation."', '".$assetName."', '".$property."', '".$internal."',
77  '".$url1."', '".$url2."', '".$url3."')"))
78  { // all good, throw success msg
79  alert::draw("success", "$lang[SUCCESS]", "$lang[ASSET_ADD_OK]", "", "1800");
80  }
81  else
82  { // failed to add new asset - throw error msg
83  alert::draw("danger", "$lang[ERROR]", "$lang[ASSET_ADD_FAILED]", "", "2600");
84  }
85  }
86 
87  // UPDATE EXISTING ASSET
88  if (isset($_GET['edit']) && $_GET['edit'] == 1)
89  {
90  // prepare user data
91  $id = $db->quote($_POST['id']);
92  $assetType = $db->quote($_POST['assetType']);
93  $assetName = $db->quote($_POST['assetName']);
94  $property = $db->quote($_POST['assetName']);
95  $internal = $db->quote($_POST['internal']);
96  $url1 = $db->quote($_POST['url1']);
97  $url2 = $db->quote($_POST['url2']);
98  $url3 = $db->quote($_POST['url3']);
99  $sortation = $db->quote($_POST['sortation']);
100 
101  // add asset to db
102  if ($db->query(("UPDATE {assets_types}
103  SET type = '" . $assetType . "',
104  asset = '" . $assetName . "',
105  property = '" . $property . "',
106  internal = '" . $internal . "',
107  url1 = '" . $url1 . "',
108  url2 = '" . $url2 . "',
109  url3 = '" . $url3 . "',
110  sortation = '" . $sortation . "'
111  WHERE id = '" . $id . "'")))
112  { // all good, throw success msg
113  alert::draw("success", "$lang[SUCCESS]", "$lang[ASSET_UPDATE_OK]", "", "800");
114  }
115  else
116  { // failed to add new asset - throw error msg
117  alert::draw("danger", "$lang[ERROR]", "$lang[ASSET_UPDATE_FAILED]", "", "2600");
118  }
119  }
120 }
121 
122 ?>
123 
124 <?php
125 // TEMPLATE WRAPPER - HEADER & breadcrumbs
126 echo "
127  <!-- Content Wrapper. Contains page content -->
128  <div class=\"content-wrapper\" id=\"content-FX\">
129  <!-- Content Header (Page header) -->
130  <section class=\"content-header\">";
131 // draw Title on top
132 echo backend::getTitle($lang['ASSETS'], $lang['SETTINGS']);
133 echo backend::getSettingsBreadcrumbs($lang);
134 echo"</section><!-- Main content -->
135  <section class=\"content\">";
136 /* page content start here */
137 ?>
138 <!-- DATABASE -->
139 <div class="box">
140  <div class="box-body">
141  <div class="col-md-12">
142  <?php echo "<h4><i class=\"fa fa-puzzle-piece\"></i> &nbsp;$lang[ASSETS]&nbsp;<small>$lang[ASSETS_SUBTEXT]</small></h4>"; ?>
143  </div>
144  </div>
145 </div>
146 <div class="row animated fadeIn">
147  <div class="col-md-8">
148  <?php
149  $res = $db->query("SELECT * FROM {assets_types} ORDER BY asset");
150  while ($row = mysqli_fetch_assoc($res))
151  {
152  if ($row['published'] == 1)
153  {
154  $assetStatus = "<i class=\"label label-success\">$lang[ONLINE]</i>";
155  }
156  else
157  {
158  $assetStatus = "<i class=\"label label-danger\">$lang[OFFLINE]</i>";
159  }
160 
161  if ($row['type'] == 1)
162  {
163  $assetType1Selected = "selected";
164  }
165  else
166  {
167  $assetType1Selected = '';
168  }
169  if ($row['type'] == 2)
170  {
171  $assetType2Selected = "selected";
172  }
173  else
174  {
175  $assetType2Selected = '';
176  }
177  if ($row['type'] == 3)
178  {
179  $assetType3Selected = "selected";
180  }
181  else
182  {
183  $assetType3Selected = '';
184  }
185  echo "
186  <!-- BOX -->
187  <div class=\"box box-default collapsed-box\">
188  <div class=\"box-header with-border\">
189  <h3 class=\"box-title\"><b>$row[sortation].</b> $row[asset] <small>$lang[EDIT]</small></h3>
190  <!-- box-tools -->
191  <div class=\"box-tools pull-right\">
192  <small><a href=\"index.php?page=settings-assets&toggle=1&published=$row[published]&id=$row[id]\">$assetStatus</a></small>
193  <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"collapse\"><i class=\"fa fa-plus\"></i>
194  </button>
195  </div>
196  <!-- /.box-tools -->
197  </div>
198  <div class=\"box-body\" style=\"display: none;\">
199  <!-- BOX BODY -->
200  <form name=\"form\" role=\"form\" action=\"index.php?page=settings-assets&edit=1&id=$row[id]\" method=\"POST\">
201  <input type=\"hidden\" class=\"form-control\" name=\"id\" value=\"$row[id]\">
202  <label for=\"assetName\">$lang[NAME]</label>
203  <input type=\"text\" class=\"form-control\" name=\"assetName\" id=\"assetName\" value=\"$row[asset]\" placeholder=\"$lang[ASSET_NAME_PH]\">
204  <label for=\"internal\">$lang[INTERNAL]</label>
205  <input type=\"text\" class=\"form-control\" name=\"internal\" id=\"internal\" value=\"$row[internal]\" placeholder=\"$lang[ASSET_INTERNAL_PH]\">
206  <label for=\"url1\">$lang[URL] 1</label>
207  <input type=\"text\" class=\"form-control\" name=\"url1\" id=\"url1\" value=\"$row[url1]\" placeholder=\"$lang[ASSET_URL_PH]\">
208  <label for=\"url2\">$lang[URL] 2</label>
209  <input type=\"text\" class=\"form-control\" name=\"url2\" id=\"url2\" value=\"$row[url2]\" placeholder=\"$lang[ASSET_URL_PH]\">
210  <label for=\"url3\">$lang[URL] 3</label>
211  <input type=\"text\" class=\"form-control\" name=\"url3\" id=\"url3\" value=\"$row[url3]\" placeholder=\"$lang[ASSET_URL_PH]\">
212  <label for=\"assetType\">$lang[TYPE]</label>
213  <select class=\"form-control\" name=\"assetType\" id=\"assetType\">
214  <option value=\"1\">$lang[PLEASE_SELECT]</option>
215  <option value=\"1\" $assetType1Selected>$lang[REQUIRED]</option>
216  <option value=\"2\" $assetType2Selected>$lang[OPTIONAL]</option>
217  <option value=\"3\" $assetType3Selected>$lang[USER_DEFINED]</option>
218  </select>
219  <label for=\"sortation\">$lang[LOADING_ORDER]</label>
220  <input type=\"text\" class=\"form-control\" name=\"sortation\" id=\"sortation\" value=\"$row[sortation]\" placeholder=\"$lang[ORDER_PH]\">
221  <a style=\"margin-top:2px;\" role=\"dialog\" data-confirm=\"$lang[ASSET_DEL] &laquo;$row[asset]&raquo;\"
222  title=\"$lang[ASSET] $lang[DELETE]\" href=\"index.php?page=settings-assets&delete=1&id=$row[id]&asset=$row[asset]\" class=\"btn btn-default pull-left\"><i class=\"fa fa-trash-o\"></i> $lang[DELETE]</a>
223  <button class=\"btn btn-success pull-right\" type=\"submit\" value=\"save\" id=\"savebutton\" title=\"$lang[SAVE]\" name=\"save\" style=\"margin-top:2px;\"><i id=\"savebuttonIcon\" class=\"fa fa-check\"></i>&nbsp;&nbsp;$lang[SAVE_SETTINGS]</button>
224  <br><br>
225  </form>
226  </div>
227  </div>";
228 
229  }
230  ?>
231  </div>
232  <div class="col-md-4">
233  <!-- add new asset form -->
234  <div class="box">
235  <div class="box-header with-border">
236  <h3 class="box-title"><?php echo $lang['ASSET']; ?> <small><?php echo $lang['ADD']; ?> </small></h3>
237  </div>
238  <div class="box-body">
239  <form name="newAsset" role="form" action="index.php?page=settings-assets&newAsset=true" method="POST">
240  <label for="assetName"><?php echo $lang['NAME']; ?></label>
241  <input type="text" class="form-control" name="assetName" id="assetName" placeholder="<?php echo $lang['ASSET_NAME_PH']; ?>">
242  <label for="internal"><?php echo $lang['INTERNAL']; ?></label>
243  <input type="text" class="form-control" name="internal" id="internal" placeholder="<?php echo $lang['ASSET_INTERNAL_PH']; ?>">
244  <label for="url1"><?php echo $lang['URL']; ?> 1</label>
245  <input type="text" class="form-control" name="url1" id="url1" placeholder="<?php echo $lang['ASSET_URL_PH']; ?>">
246  <label for="url2"><?php echo $lang['URL']; ?> 2</label>
247  <input type="text" class="form-control" name="url2" id="url2" placeholder="<?php echo $lang['ASSET_URL_PH']; ?>">
248  <label for="url3"><?php echo $lang['URL']; ?> 3</label>
249  <input type="text" class="form-control" name="url3" id="url3" placeholder="<?php echo $lang['ASSET_URL_PH']; ?>">
250  <label for="assetType"><?php echo $lang['TYPE']; ?></label>
251  <select class="form-control" name="assetType" id="assetType">
252  <option value="1"><?php echo $lang['REQUIRED']; ?></option>
253  <option value="2" selected><?php echo $lang['OPTIONAL']; ?></option>
254  <option value="3"><?php echo $lang['USER_DEFINED']; ?></option>
255  </select>
256  <button class="btn btn-success pull-right" id="newAsset" name="newAsset" style="margin-top:2px;"><i id="savebuttonIcon" class="fa fa-check"></i>&nbsp;&nbsp;<?php echo $lang['ASSET_ADD']; ?></button>
257  </form>
258  </div>
259  </div>
260  </div>
261 </div>
print $lang['FILEMAN_UPLOAD']
Throws a fancy Bootstrap Alert (success, info, warning or danger)
Definition: alert.php:19
Backend class serves a few useful functions for the admin backend.
Definition: backend.php:27
Mysqli database class; returns db connection object.
Definition: db.php:16
The language class - support multilingual backend.
Definition: language.php:17
if(!isset($db)) $id
type
Definition: menu-new.php:35
print $_GET['id']
Definition: page-edit.php:357
function i(e, t)
Definition: plyr.js:1
<!-- backend language -->< h3 >< i class="fa fa-language"></i > & nbsp
$template name