<?php include('../config.php'); include('../functions.php'); include('../classes/anytable.class.php'); include('../classes/isincollection.class.php'); include('../classes/currencycollection.class.php'); loginAdmin(); if(!loggedAdmin()) header('location: index.php'); if(exist($_POST['add'])) { $result = IsinCollection::addIsin(); if(!count($result)) header("location: isins_created.php"); } include("$templates/menu.php"); $currencies = CurrencyCollection::getCurrencies(); include("$templates/isins_add.php"); include("$templates/footer.php"); ?>
static public function verifyFields() { foreach($_POST as $key=>$value) $_POST[$key] = mysql_real_escape_string($value); $errors=''; $fields = array('currency','client','aname','amount','credit','valuec','debit','valued'); $fieldsDates = array('valuec','valued'); $fieldsNumbers= array('amount','credit','debit'); $fieldsObligatory = array('currency','client','aname','amount'); $errorMessage = array('Currency','Client','Account name','Amount'); $errorMessageDates= array('Credit date (should be YYYY-MM-DD)','Debit date (should be YYYY-MM-DD)'); $errorMessageNumbers= array('Amount should be number','Credit should be number','Debit should be number'); $result = array(); foreach($fieldsObligatory as $key=>$field): if(!exist($_POST[$field])) $result[] = $errorMessage[$key]; endforeach; foreach($fieldsDates as $key=>$field) if(trim($_POST[$field])) if(trim($_POST[$field]) !== '0000-00-00') if((!preg_match("/[0-9]{4}-[0-9]{2}-[0-9]{2}$/", $_POST[$field]))||(strtotime(trim($_POST[$field]))<1)) $result[] = $errorMessageDates[$key]; foreach($fieldsNumbers as $key=>$field) if(trim($_POST[$field])) if(!preg_match("/^[\d]{0,8}$/", $_POST[$field])) $result[] = $errorMessageNumbers[$key]; if(trim($_POST['client'])) if(!ClientCollection::getClients(trim($_POST['client']))) die('Database error: not existant client.. please apply admin'); if(trim($_POST['currency'])) if(!CurrencyCollection::getCurrencies(trim($_POST['currency']))) die('Database error: not existant currency.. please apply admin'); return $result; }