public function postshopdata() { $file = Input::file('shopdata'); $destinationPath = 'importdata'; // If the uploads fail due to file system, you can try doing public_path().'/uploads' $filename = 'imported-shoppinglistdata'; //$filename = $file->getClientOriginalName(); //$extension =$file->getClientOriginalExtension(); $upload_success = Input::file('shopdata')->move($destinationPath, $filename . '.' . $file->getClientOriginalExtension()); if ($upload_success) { $importedFile = public_path() . '/importdata/' . $filename . '.' . $file->getClientOriginalExtension(); Excel::load($importedFile, function ($r) { $res = $r->all()->toArray(); foreach ($res as $data) { if ($data['kode'] != '' && $data['deskripsi'] != '' && $data['satuan'] != '' && $data['harga'] != '') { $d = new ShoppingList(); $d->kode_sl = $data['kode']; $d->deskripsi_pekerjaan = $data['deskripsi']; $d->satuan = $data['satuan']; $d->harga = $data['harga']; $d->save(); } } }); Session::flash('success', 'Shoppinglist Data imported to database'); return Redirect::to('/import'); } else { Session::flash('error', 'Error uploading files'); return Redirect::to('/import'); } }
public function data() { $active = "oss"; $approvals = ApprovalPerson::all(); $sl_data = ShoppingList::all(); $dataoss = Oss::all(); $sites = Mastertp::distinct()->groupBy('sitelocation')->get(); $max = 1; $nomax = DB::table('oss')->orderBy('no_oss', 'desc')->take(1)->get(); foreach ($nomax as $nomax) { $max = $nomax->no_oss; $max = $max + 1; } return View::make('oss.list')->with('active', $active)->with('dataoss', $dataoss)->with('max', $max)->with('sites', $sites)->with('sl_data', $sl_data)->with('approvals', $approvals); }
} if (isset($_POST['quantity'])) { $quantity = $_POST['quantity']; //obtenemos la cantidad a comprar del item a partir de la variable POST } else { //die ('No se ha seleccionado una cantidad comprada'); } if (isset($_POST['quantityBought'])) { $quantityBought = $_POST['quantityBought']; //obtenemos la cantidad comprada del item a partir de la variable POST } else { //die ('No se ha seleccionado una cantidad comprada'); } //comprobamos que el usuario se ha autenticado y pertenece al grupo a cuya lista pertenece el item a marcar como comprado $currentUser = User::getLoggedInUser(); if (!$currentUser) { die('Necesitas autenticarte para acceder a esta funcionalidad'); } if (!Item::userBelongsToGroupOfItemList($currentUser->id, $idList, $idItem)) { die("No perteneces al grupo de la lista cuyos productos quieres listar"); } $item = new Item(); $item->idItem = $idItem; $item->quantity = $quantity; $item->quantityBought = $quantityBought; $item->buyItem(); //comprobamos si el item que se acaba de comprar ha completado la lista if (ShoppingList::isCompleted($idList)) { //informamos de que se han marcado todos los items como comprados echo "closed"; }
} session_start(); $idGroup; if (isset($_SESSION['idGroup'])) { $idGroup = $_SESSION['idGroup']; //obtenemos el id del grupo a partir de la sesión } else { if (isset($_POST['idGroup'])) { $idGroup = $_POST['idGroup']; //obtenemos el id del grupo a partir de la variable POST } else { die('No se ha seleccionado un grupo'); } } //comprobamos que el usuario se ha autenticado y pertenece al grupo cuyas listas quiere listar $currentUser = User::getLoggedInUser(); if (!$currentUser) { die('Necesitas autenticarte para acceder a esta funcionalidad'); } if (!Group::userBelongsToGroup($currentUser->id, $idGroup)) { die("No perteneces al grupo con id {$idGroup}!"); } //insertamos la nueva lista en la base de datos $list = new ShoppingList(array('listName' => $listName, 'idGroup' => $idGroup)); $list->insert(); //insertamos todos los productos iniciales para la lista anteriormente creada foreach ($newList[1] as $product) { $item = new Item(array('idList' => $list->idList, 'itemName' => $product->prodName, 'quantity' => $product->prodQt, 'metric' => 'u')); $item->insertItem(); } echo 'success';
} else { //die ('No se ha seleccionado un item'); } if (isset($_POST['quantity'])) { $quantity = $_POST["quantity"]; //obtenemos la cantidad del item a partir de la variable POST } else { //die ('No se ha seleccionado un item'); } if (isset($_POST['metric'])) { $metric = $_POST["metric"]; //obtenemos la cantidad del item a partir de la variable POST } else { //die ('No se ha seleccionado un item'); } //comprobamos que el usuario se ha autenticado y pertenece al grupo en cuya lista se encuentra el item eliminar $currentUser = User::getLoggedInUser(); if (!$currentUser) { die('Necesitas autenticarte para acceder a esta funcionalidad'); } if (!ShoppingList::userBelongsToGroupOfList($currentUser->id, $idList)) { die("No perteneces al grupo de la lista con id {$idList}!"); } $item = new Item(); $item->idList = $idList; $item->itemName = $itemName; $item->itemState = false; $item->quantity = $quantity; $item->quantityBought = 0; $item->metric = $metric; $item->insertItem();
/** Returns an array with all the current ingredients in it for this recipe @param $servings the number of servings to scale the ingredients to @param $optional if true then the optional ingredients are returned as well */ function getIngredients($servings = NULL, $optional = FALSE) { global $DB_LINK, $db_table_ingredientmaps; $ingredients = array(); $scaling = null; // compute the scaling if ($this->serving_size != 0 && $this->serving_size != "") { $scaling = $servings / $this->serving_size; } if ($scaling == NULL || $servings == 0) { $scaling = 1; } $sql = "SELECT * FROM {$db_table_ingredientmaps} WHERE map_recipe=" . $DB_LINK->addq($this->id, get_magic_quotes_gpc()); $rc = $DB_LINK->Execute($sql); while (!$rc->EOF) { // Only add the ingredient if we are suppose to if ($optional && $rc->fields['map_optional'] == $DB_LINK->true || $rc->fields['map_optional'] != $DB_LINK->true) { $ingObj = new Ingredient(); $ingObj->setIngredientMap($rc->fields['map_ingredient'], $rc->fields['map_recipe'], $rc->fields['map_qualifier'], $rc->fields['map_quantity'], $rc->fields['map_unit'], $rc->fields['map_order']); $ingObj->loadIngredient(); $ingObj->convertToBaseUnits($scaling); $ingredients = ShoppingList::combineIngredients($ingredients, $ingObj); } $rc->MoveNext(); } return $ingredients; }
echo $LangUI->_('List Name'); ?> : <input type="text" name="list_name" value="<?php echo htmlentities($_GET["list_name"], ENT_QUOTES); ?> "> <input type="submit" value="<?php echo $LangUI->_('Update'); ?> "> </form> <!-- End of Edit form --> <?php } else { if ($mode == "edit_confirm") { $listObj = new ShoppingList(htmlentities($_POST["list_id"], ENT_QUOTES), htmlentities($_POST["list_name"], ENT_QUOTES)); $listObj->updateListName(); echo $LangUI->_('List Name Updated.') . "<br />"; } } } if ($mode != "edit") { // spit out a list of list names to choose from $counter = 0; $sql = "SELECT * FROM {$db_table_list_names} WHERE list_user='******'"; $rc = $DB_LINK->Execute($sql); if ($rc->RecordCount() > 0) { ?> <table cellspacing="1" cellpadding="2" border=0 width="95%" class="data"> <tr> <th><?php
$target.css('text-decoration', 'line-through'); $target.css('background', '#E0E0E0'); $target.css('border-color', '#C2C2C2'); } else { $target.css('text-decoration', ''); $target.css('background', ''); } } </script> <br/> <ul data-role="listview" id="currentList" data-inset="false" data-theme="e" data-dividertheme="b"> <?php $listObj = new ShoppingList(); $listObj->loadCurrentListId(); $listObj->loadItems(true); // Cycle through the ingredients now (if any) $locationName = ""; foreach ($listObj->ingredients as $ingObj) { if ($ingObj->locationDescription != "" && $ingObj->locationDescription != $locationName) { echo "<li data-role=\"list-divider\">{$ingObj->locationDescription}</li>"; $locationName = $ingObj->locationDescription; } ?> <li id="listIngredient_<?php echo $ingObj->id; ?> " onclick="removeItem('listIngredient_<?php echo $ingObj->id;
public function read() { return ShoppingList::calculate($this->params); }
<?php require_once "User.php"; require_once "ShoppingList.php"; session_start(); if (isset($_POST['idList'])) { $idList = $_POST['idList']; //obtenemos el id de la lista a partir de la variable POST } else { if (isset($_SESSION['idList'])) { $idList = $_SESSION['idList']; //obtenemos el id de la lista a partir de la variable POST } else { //die ('No se ha seleccionado una lista'); } } //comprobamos que el usuario se ha autenticado y pertenece al grupo cuya lista quiere listar $currentUser = User::getLoggedInUser(); if (!$currentUser) { die('Necesitas autenticarte para acceder a esta funcionalidad'); } if (!ShoppingList::userBelongsToGroupOfList($currentUser->id, $idList)) { die("No perteneces al grupo de la lista!"); } // cerramos la lista con identificador idList ShoppingList::openList($idList);
/** * Comprueba si el usuario 'idUser' pertenece al grupo al que pertenece la lista del item 'idList' * * @param int $idUser El ID del usuario que se quiere comprobar * @param int $idItem El ID del item de la lista cuyo grupo se quiere comprobar la pertenencia * @return boolean Devuelve true si, y solo si, el usuario con id 'idUser' pertenece al grupo de la lista del item con id 'idList' */ public static function userBelongsToGroupOfItemList($idUser, $idList, $idItem) { $con = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DBNAME); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } $idSList = mysqli_real_escape_string($con, $idList); $idSItem = mysqli_real_escape_string($con, $idItem); $sql = "SELECT `idList` FROM `Item` WHERE idItem='" . $idSItem . "'"; $result = mysqli_query($con, $sql); $row = mysqli_fetch_array($result); mysqli_close($con); $idListItem = $row['idList']; if ($idListItem == $idSList) { return ShoppingList::userBelongsToGroupOfList($idUser, $idListItem); } else { return false; } }
<?php require_once "ShoppingList.php"; $idList = $_POST["idList"]; ShoppingList::createSListSession($idList);
$html = showLostIngredients($items, "remove_item_"); if (count($html) > 0) { echo '<tr><th colspan=3 align="left">' . $LangUI->_("Ingredients Without A Matching Section") . "</th></tr>"; foreach ($html as $line) { echo $line; } } ?> </table> <?php } else { if ($mode == "save") { if ($SMObj->getUserLoginID() == "") { die($LangUI->_('You do not have sufficient privileges to save/load shopping lists.')); } $saveListObj = new ShoppingList(); foreach ($useLayout as $section) { for ($i = 0; $i < count($items); $i++) { $ingObj = $items[$i]; if ($section == '' || $ingObj->location == $section) { $removeKey = "remove_item_" . $ingObj->id; if (!isset($_REQUEST[$removeKey]) || $_REQUEST[$removeKey] != "yes") { $saveListObj->addIngredient($ingObj); } } } } $saveListObj->saveAsCurrentList(); echo "<br/><br/>List Saved"; } }
<?php require_once "User.php"; require_once "ShoppingList.php"; session_start(); if (isset($_POST['idList'])) { $idList = $_POST['idList']; //obtenemos el id de la lista a partir de la variable POST } else { if (isset($_SESSION['idList'])) { $idList = $_SESSION['idList']; //obtenemos el id de la lista a partir de la variable SESSION } else { //die ('No se ha seleccionado una lista'); } } //comprobamos que el usuario se ha autenticado y pertenece al grupo cuya lista quiere listar $currentUser = User::getLoggedInUser(); if (!$currentUser) { die('Necesitas autenticarte para acceder a esta funcionalidad'); } if (!ShoppingList::userBelongsToGroupOfList($currentUser->id, $idList)) { die("No perteneces al grupo de la lista!"); } // cerramos la lista con identificador idList ShoppingList::closeList($idList);
<?php require_once "User.php"; require_once "ShoppingList.php"; //comprobamos que el usuario se ha autenticado session_start(); $currentUser = User::getLoggedInUser(); if (!$currentUser) { die('Necesitas autenticarte para acceder a esta funcionalidad'); } //comprobamos si se ha seleccionado una lista de compra if (isset($_POST['idList'])) { $idList = $_POST['idList']; //obtenemos el id de la lista a partir de la variable POST } else { if (isset($_SESSION['idList'])) { $idList = $_SESSION['idList']; //obtenemos el id de la lista a partir de la variable POST } else { //die ('No se ha seleccionado una lista'); } } //comprobamos si el usuario autenticado está autorizado a borrar esta lista if (!ShoppingList::userBelongsToGroupOfList($currentUser->id, $idList)) { die("No perteneces al grupo de la lista con id {$idList}!"); } // eliminamos la lista con identificador idList ShoppingList::deleteList($idList); //indicamos que la operación ha finalizado con éxito echo 'success';
| Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | */ Route::get('/', function () { return View::make('fronts.login'); }); Route::get('/sl', function () { Excel::load('importdata/sl.xls', function ($r) { $res = $r->all()->toArray(); foreach ($res as $data) { $d = new ShoppingList(); $d->kode_sl = $data['kode_sl']; $d->deskripsi_pekerjaan = $data['deskripsi_pekerjaan']; $d->satuan = $data['satuan']; $d->harga = $data['harga']; $d->save(); } }); }); Route::post('/auth', 'SessionController@auth'); Route::get('/logout', 'SessionController@logout'); Route::group(array('prefix' => 'home', 'before' => 'auth'), function () { Route::get('/', 'HomeController@dash'); }); Route::group(array('prefix' => 'users', 'before' => 'auth'), function () { Route::get('/', 'UserController@data');
if (isset($_POST['idGroup'])) { $idGroup = $_POST['idGroup']; //obtenemos el id del grupo a partir de la variable POST } else { die('No se ha seleccionado un grupo'); } } //comprobamos que el usuario se ha autenticado y pertenece al grupo cuyas listas quiere listar $currentUser = User::getLoggedInUser(); if (!$currentUser) { die('Necesitas autenticarte para acceder a esta funcionalidad'); } if (!Group::userBelongsToGroup($currentUser->id, $idGroup)) { die("No perteneces al grupo con id {$idGroup}!"); } $con = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DBNAME); if (!$con) { die('No se ha podido conectar: ' . mysqli_error($con)); } //obtenemos el nombre del grupo actualmente seleccionado $sql = "SELECT * FROM `Group` WHERE idGroup = {$idGroup}"; $result = mysqli_query($con, $sql); $row = mysqli_fetch_array($result); $groupName = $row['groupName']; //obtenemos las listas de compra del grupo actualmente seleccionado $lists = ShoppingList::listSLists($idGroup); //juntamos el nombre del grupo y sus listas de compra en un array $groupAndSLists = array('groupName' => $groupName, 'slists' => $lists); //lo codificamos en JSON y lo enviamos al usuario mysqli_close($con); echo json_encode($groupAndSLists);