public function testCodeIsNew() { $C = new Codes(); $not_new_code = $C->generateCode(); $C->codeIsNew($not_new_code); $new_code = $C->generateCode(); // && $C->codeIsNew($new_code) $existing_code = 'RICK9TQX4H'; $this->assertTrue($C->codeIsNew($existing_code) == false); }
public static function addCodesType() { DB::escapePost(); if (!$_POST['multiple']) { $sql = ' INSERT INTO {{codes_type}} SET name=\'' . $_POST['name'] . '\', fromdate=\'' . date('Y-m-d H:i:01', strtotime($_POST['fromdate'])) . '\', todate=\'' . date('Y-m-d H:i:01', strtotime($_POST['todate'])) . '\', ctype=\'' . $_POST['type'] . '\', value=\'' . $_POST['value'] . '\', comment=\'' . $_POST['comment'] . '\', cdate=NOW(), author=\'' . $_SESSION['user']['login'] . ' ' . $_SESSION['user']['name'] . '\', visible=1 '; //print DB::prefix($sql).'<br>'; $id = DB::exec($sql); for ($i = 0; $i < $_POST['num']; $i++) { $code = Codes::generateCode(); $sql = ' INSERT INTO {{codes}} SET ctype=' . $id . ', code=\'' . $code . '\' '; //print DB::prefix($sql).'<br>'; DB::exec($sql); } //die; } else { $sql = ' INSERT INTO {{codes_type}} SET name=\'' . $_POST['name'] . '\', fromdate=\'' . date('Y-m-d H:i:01', strtotime($_POST['fromdate'])) . '\', todate=\'' . date('Y-m-d H:i:01', strtotime($_POST['todate'])) . '\', ctype=\'' . $_POST['type'] . '\', code=\'' . $_POST['code'] . '\', value=\'' . $_POST['value'] . '\', num=\'' . $_POST['num'] . '\', comment=\'' . $_POST['comment'] . '\', cdate=NOW(), author=\'' . $_SESSION['user']['login'] . ' ' . $_SESSION['user']['name'] . '\', visible=1 '; $id = DB::exec($sql); } }