-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply_for_tender_api.php
More file actions
71 lines (60 loc) · 3.16 KB
/
apply_for_tender_api.php
File metadata and controls
71 lines (60 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
session_start();
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: PUT");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// include database file
include_once 'mongodb_config.php';
include 'GeneralTenderForm.php';
class ApplyTender extends GeneralTenderForm{
public $dbname = 'tender';
public $collection;
public $db;
public $conn;
public function __construct(){
$this->dbname = "tender";
$this->collection = "tender_form";
$this->db = new DbManager();
$this->conn = ( $this->db)->getConnection();
}
public function checkIfAlreadyApplied(){
$filter = ['comp_id' => $_SESSION['company_id'], 'tender_id' => $_POST['tender_id'], 'category' => $_POST['chosencategory']];
$option = [ 'projection' => [ 'description'=> 1]];
$read = new MongoDB\Driver\Query($filter, $option);
//fetch records
$records = $this->conn->executeQuery("$this->dbname.$this->collection", $read);
$array = iterator_to_array($records);
if( count($array) != 1)
return false;
else
return true;
}
public function setFormValue( $tender_id, $compid, $compid_owner, $category, $contracttitle, $description, $reference, $estimatedtime, $agreementvalue, $dateinvited, $datedue, $conditions, $openclose, $whyiamspecial, $comp_estimate){
$this->setGeneralValuesForTenderApply( $tender_id, $compid, $compid_owner, $category, $contracttitle, $description, $reference, $estimatedtime, $agreementvalue, $dateinvited, $datedue, $conditions, $openclose, $whyiamspecial, $comp_estimate);
$updateInfoInProperFormat = $this->formatTenderApplyDataForInsertionInDB();
$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert( $updateInfoInProperFormat);
$result = $this->conn->executeBulkWrite("$this->dbname.$this->collection", $bulk);
if( $result == TRUE){
echo [ 'success'=>1];
}
else{
echo [ 'success'=>0];
}
}
}
$applyTenderObject = new ApplyTender();
if($applyTenderObject->checkIfAlreadyApplied()){
header('location:tenderViewPage.php?applied=2');
}
else{
$applyTenderObject->setFormValue( $_POST['tender_id'], $_SESSION["company_id"], $_POST['comp_id_owner'], $_POST["chosencategory"], $_POST["contracttitle"], $_POST["description"], $_POST["reference"], $_POST["estimated_time"], $_POST["agreement_value"], $_POST["date_invited"], $_POST["date_due"], $_POST["conditions"], 1, $_POST["whyiamspecial"], $_POST["comp_estimate"] );
header('location:tenderViewPage.php?applied=1');
}
//applied = 2 means already applied by the company
//applied = 1 means applied successfully ( not used till now)
//applied = 0 means unsuccessful ( not used till now)
?>