function update_unit($unitInfo) { if (!isset($unitInfo['id'])) { throw new Exception("Product id required."); } $id = $unitInfo['id']; $dbh = new PDOConnection(); $oldValues = get_units(array('id' => $id))[0]; //returns array of units if (empty($oldValues)) { throw new Exception("Product id: '" . $id . "' not found!"); } $query = "UPDATE units \n SET code = :code, \n description = :description, \n active = :active\n WHERE id = :id"; $sth = $dbh->prepare($query); $code = isset($unitInfo['code']) ? $unitInfo['code'] : $oldValues['code']; $description = isset($unitInfo['description']) ? $unitInfo['description'] : $oldValues['description']; $active = isset($unitInfo['active']) ? $unitInfo['active'] : $oldValues['active']; $sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->bindParam(':code', $code); $sth->bindParam(':description', $description); $sth->bindParam(':active', $active, PDO::PARAM_INT); if (!$sth->execute()) { throw new Exception($sth->errorInfo()[2]); } return true; }
function is_teacher_max_e($emp_id, $subject_code_2add, $class_id) { if ($emp_id == "NULL") { return NULL; } $query = mysql_query("SELECT * FROM teacher_t WHERE emp_id='{$emp_id}'") or die("error selecting teach"); $row = mysql_fetch_assoc($query); $max_load = $row['max_load']; //insert codes for getting the current school year $sy_id = get_active_sy(); $total_units = 0; $query2 = mysql_query("SELECT * FROM class_t WHERE teacher_id='{$emp_id}' AND sy_id='{$sy_id}' AND class_id<>'{$class_id}'") or die(mysql_error()); while ($row2 = mysql_fetch_assoc($query2)) { $subject_code = $row2['subject_code']; $total_units += get_units($subject_code); } $total_units += get_units($subject_code_2add); if ($total_units > $max_load) { return "Teaching load exceeded the maximum allowed value ({$total_units}/{$max_load})"; } else { return NULL; } }
$responseArray['response'] = get_product_classes($values); $responseArray['message'] = 'Classes successfully read'; break; case 'update_product_class': include_once __DIR__ . '/products/update_product_class.php'; update_product_class($values); $responseArray['message'] = 'Product class successfully updated'; break; case 'add_unit': include_once __DIR__ . '/products/add_unit.php'; add_unit($values); $responseArray['message'] = 'Unit successfully added'; break; case 'get_units': include_once __DIR__ . '/products/get_units.php'; $responseArray['response'] = get_units($values); $responseArray['message'] = 'Units successfully read'; break; case 'update_unit': include_once __DIR__ . '/products/update_unit.php'; $responseArray['response'] = update_unit($values); $responseArray['message'] = 'Successfully updated unit'; break; case 'add_product_unit': include_once __DIR__ . '/products/add_product_unit.php'; add_product_unit($values); $responseArray['message'] = 'Product/unit successfully added'; break; case 'get_product_units': include_once __DIR__ . '/products/get_product_units.php'; $responseArray['response'] = get_product_units($values);