/** * set up for dependent objects before running each test */ public final function setUp() { //run default set-up method parent::setUp(); //create a new organization for the test volunteers to belong $organization = new Organization(null, "123 Easy Street", '', "Albuquerque", "Feeding people since 1987", "9 - 5", "Food for Hungry People", "505-765-4321", "NM", "R", "87801"); $organization->insert($this->getPDO()); //create a new volunteer to use as an admin for the tests //don't need to insert them into the database: just need their info to create sessions //for testing purposes, allow them to create organizations they're not associated with $salt = bin2hex(openssl_random_pseudo_bytes(32)); $hash = hash_pbkdf2("sha512", "password4321", $salt, 262144, 128); $this->admin = new Volunteer(null, $organization->getOrgId(), "*****@*****.**", null, "John", $hash, true, "Doe", "505-123-4567", $salt); $this->admin->insert($this->getPDO()); //create a non-admin volunteer for the tests $salt = bin2hex(openssl_random_pseudo_bytes(32)); $hash = hash_pbkdf2("sha512", "password1234", $salt, 262144, 128); $this->volunteer = new Volunteer(null, $organization->getOrgId(), "*****@*****.**", null, "Jane", $hash, false, "Doe", "505-555-5555", $salt); $this->volunteer->insert($this->getPDO()); //create the guzzle client $this->guzzle = new \GuzzleHttp\Client(["cookies" => true]); //visit ourselves to get the xsrf-token $this->guzzle->get('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/organization'); $cookies = $this->guzzle->getConfig()["cookies"]; $this->token = $cookies->getCookieByName("XSRF-TOKEN")->getValue(); //send a request to the sign-in method $adminLogin = new stdClass(); $adminLogin->email = "*****@*****.**"; $adminLogin->password = "******"; $login = $this->guzzle->post('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/controllers/sign-in-controller.php', ['json' => $adminLogin, 'headers' => ['X-XSRF-TOKEN' => $this->token]]); }
/** * Save a new organization with the minimal information * @return an array with result and message json encoded */ public function run() { $controller = $this->getController(); // Retrieve data from form $newOrganization = Organization::newOrganizationFromPost($_POST); try { //Save the organization Rest::json(Organization::insert($newOrganization, Yii::app()->session["userId"])); } catch (CTKException $e) { return Rest::json(array("result" => false, "msg" => $e->getMessage())); } }
throw new InvalidArgumentException("password cannot be empty", 405); } // sanitize the email & search by volEmail $volEmail = filter_var($requestObject->volEmail, FILTER_SANITIZE_EMAIL); $volunteer = Volunteer::getVolunteerByVolEmail($pdo, $volEmail); if ($volunteer !== null) { throw new RuntimeException("This email already has an account", 422); } // create a new salt and email activation $volSalt = bin2hex(openssl_random_pseudo_bytes(32)); $volEmailActivation = bin2hex(openssl_random_pseudo_bytes(8)); // create the hash $volHash = hash_pbkdf2("sha512", $requestObject->password, $volSalt, 262144, 128); //create a new organization and insert into mySQL $organization = new Organization(null, $requestObject->orgAddress1, $requestObject->orgAddress2, $requestObject->orgCity, $requestObject->orgDescription, $requestObject->orgHours, $requestObject->orgName, $requestObject->orgPhone, $requestObject->orgState, $requestObject->orgType, $requestObject->orgZip); $organization->insert($pdo); $reply->message = "New organization has been created"; //create a new Volunteer and insert into mySQL $volunteer = new Volunteer(null, $organization->getOrgId(), $requestObject->volEmail, $volEmailActivation, $requestObject->volFirstName, $volHash, true, $requestObject->volLastName, $requestObject->volPhone, $volSalt); $volunteer->insert($pdo); $reply->message = "A new administrator has been created"; if ($volunteer->getVolIsAdmin() === true) { $_SESSION["volunteer"] = $volunteer; $reply->status = 200; $reply->message = "Logged in as administrator"; } // create Swift message $swiftMessage = Swift_Message::newInstance(); // attach the sender to the message // this takes the form of an associative array where the Email is the key for the real name $swiftMessage->setFrom(["*****@*****.**" => "Bread Basket"]);
$udata['vAddressLine2'] = $_POST['vAddressLine2']; $udata['vAddressLine3'] = $_POST['vAddressLine3']; $udata['vCity'] = $_POST['vCity']; $udata['vCountry'] = $_POST['vCountry']; $udata['vState'] = $_POST['vState']; $udata['vZipcode'] = $_POST['vZipcode']; $udata['vPhone'] = $odata['vPhone']; $udata['eUserType'] = 'Admin'; $udata['eSelfReg'] = 'Yes'; // $udata['vActivationCode'] = $activationcode; $udata['dCreatedDate'] = $udata['dModifiedDate'] = calcGTzTime(date('Y-m-d H:i:s'), 'Y-m-d H:i:s'); $udata['eStatus'] = 'Need to Verify'; // pr($_POST); $odata['vOrganizationCode'] = $orgObj->getUniqueCode($odata['eOrganizationType']); // pr($odata); $oid = $res = $orgObj->insert($odata); if ($oid > 0) { $odata['iOrganizationID'] = $oid; $res = $orgvrfObj->insert($odata); // $udata['iOrganizationID'] = $oid; $uid = $orgUsrObj->insert($udata); if ($uid > 0) { $udata['iUserID'] = $uid; $iVerifiedID = $userToVerifyObj->insert($udata); } // echo $uid; exit; // org default preferences //------------------------DEFALT VALUES OF PURCHASE ORDER -----------------------------------------// if ($odata['eOrganizationType'] != 'Supplier') { $where = ' AND eFor = "PO" AND eType = "Default" AND eStatus = "Active"';
/** * function to map the ralated to (organization) for potentials while importing * checks if the organization exists else will add a new one * @param string $organization_name * @return integer idorganization */ public function map_related_to_organization($organization_name) { if (strlen($organization_name) > 2) { $organization_name = trim($organization_name); $do_organization = new Organization(); $qry = "\n\t\t\tselect `idorganization` \n\t\t\tfrom `organization` \n\t\t\twhere \n\t\t\t`organization_name` = ?\n\t\t\tAND `deleted` = 0 \n\t\t\tAND `iduser` = " . $_SESSION["do_user"]->iduser; $do_organization->query($qry, array($organization_name)); if ($do_organization->getNumRows() > 0) { $do_organization->next(); return $do_organization->idorganization; } else { $do_organization->insert("organization", array("organization_name" => CommonUtils::purify_input($organization_name), "iduser" => $_SESSION["do_user"]->iduser)); $idorganization = $do_organization->getInsertId(); //adding the added_on $q_upd = "\n\t\t\t\tupdate `organization`\n\t\t\t\tset `added_on` = '" . date("Y-m-d H:i:s") . "'\n\t\t\t\twhere `idorganization` = " . $idorganization; $do_organization->query($q_upd); $do_organization->insert("organization_custom_fld", array("idorganization" => $idorganization)); $do_organization->insert("organization_address", array("idorganization" => $idorganization)); $do_data_history = new DataHistory(); $do_data_history->add_history($idorganization, 6, 'add'); $do_data_history->free(); return $idorganization; } } }
/** * When an initation to join an organization network is sent : * this method will : * 1. Create a new person and organization. * 2. Make the new person a member and admin of the organization * 3. Join the network of the organization inviting * @param type $person the minimal data to create a person * @param type $organization the minimal data to create an organization * @param type $parentOrganizationId the organization Id to join the network of * @return newPersonId ans newOrganizationId */ public static function createPersonOrganizationAndAddMember($person, $organization, $parentOrganizationId) { //The data check is normaly done before inserting but the both data (organization and person) //must be ok before inserting //Check person datas Person::getAndcheckPersonData($person, false); //Check organization datas Organization::getAndCheckOrganization($organization); //Create a new person $newPerson = Person::insert($person); //Create a new organization $newOrganization = Organization::insert($organization, $newPerson["id"]); //Link the person as an admin Link::addMember($newOrganization["id"], Organization::COLLECTION, $newPerson["id"], PHType::TYPE_CITOYEN, $newPerson["id"], true); //Link the organization as a member of the invitor //TODO SBAR - On GRANDDIR case, the parent organization can manage (data, event, project...) their organization members. //Should be a parameter of the application. $isParentOrganizationAdmin = true; Link::addMember($parentOrganizationId, Organization::COLLECTION, $newOrganization["id"], Organization::COLLECTION, $newPerson["id"], $isParentOrganizationAdmin); return array("result" => true, "msg" => Yii::t("organisation", "The invitation process completed with success"), "id" => $newOrganization["id"]); }
/** * test grabbing an organization by zip code */ public function testGetValidOrganizationByZip() { //count the number of rows currently in the database $numRows = $this->getConnection()->getRowCount("organization"); //create a new organization and insert into mySQL $organization = new Organization(null, $this->VALID_ADDRESS1, $this->VALID_ADDRESS2, $this->VALID_CITY, $this->VALID_DESCRIPTION, $this->VALID_HOURS, $this->VALID_NAME, $this->VALID_PHONE, $this->VALID_STATE, $this->VALID_TYPE, $this->VALID_ZIP); $organization->insert($this->getPDO()); //grab data from mySQL and enforce that the fields match $pdoOrganization = Organization::getOrganizationByOrgZip($this->getPDO(), $this->VALID_ZIP); $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("organization")); $this->assertSame($pdoOrganization[0]->getOrgAddress1(), $this->VALID_ADDRESS1); $this->assertSame($pdoOrganization[0]->getOrgAddress2(), $this->VALID_ADDRESS2); $this->assertSame($pdoOrganization[0]->getOrgCity(), $this->VALID_CITY); $this->assertSame($pdoOrganization[0]->getOrgDescription(), $this->VALID_DESCRIPTION); $this->assertSame($pdoOrganization[0]->getOrgHours(), $this->VALID_HOURS); $this->assertSame($pdoOrganization[0]->getOrgName(), $this->VALID_NAME); $this->assertSame($pdoOrganization[0]->getOrgPhone(), $this->VALID_PHONE); $this->assertSame($pdoOrganization[0]->getOrgState(), $this->VALID_STATE); $this->assertSame($pdoOrganization[0]->getOrgType(), $this->VALID_TYPE); $this->assertSame($pdoOrganization[0]->getOrgZip(), $this->VALID_ZIP); }
public static function importMongoDB2($post) { /***** new version *****/ $newFolder = false; $path = '../../modules/cityData/importData/'; if (!file_exists($path)) { mkdir($path, 0775); } $pathFile = '../../modules/cityData/importData/' . $post['nameFile'] . '/'; if (!file_exists($pathFile)) { mkdir($pathFile, 0775); $count = 1; $newFolder = true; } else { $files = scandir($pathFile); $count = 1; foreach ($files as $key => $value) { $name_file = explode(".", $value); if (strpos($name_file[0], "cityData") !== false) { $count++; } } } //importmongo all if (file_exists("../../modules/cityData/importData/importAllMongo.sh") == true) { $textImportMongoAll = file_get_contents("../../modules/cityData/importData/importAllMongo.sh", FILE_USE_INCLUDE_PATH); } else { $textImportMongoAll = ""; } if ($newFolder) { $textImportMongoAll = $textImportMongoAll . "cd " . $post['nameFile'] . ";\n"; $textImportMongoAll = $textImportMongoAll . "sh importMongo.sh;\n"; $textImportMongoAll = $textImportMongoAll . "cd .. ;\n"; } //importmongo if (file_exists("../../modules/cityData/importData/" . $post['nameFile'] . "/importMongo.sh") == true) { $textFileSh = file_get_contents("../../modules/cityData/importData/" . $post['nameFile'] . "/importMongo.sh", FILE_USE_INCLUDE_PATH); } else { $textFileSh = ""; } $textFileSh = $textFileSh . "mongoimport --db pixelhumain --collection organizations " . $post['nameFile'] . "_" . $count . ".json --jsonArray;\n"; file_put_contents("../../modules/cityData/importData/" . $post['nameFile'] . "/" . $post['nameFile'] . "_" . $count . ".json", $post['jsonImport']); file_put_contents("../../modules/cityData/importData/" . $post['nameFile'] . "/error_" . $count . ".json", $post['jsonError']); file_put_contents("../../modules/cityData/importData/" . $post['nameFile'] . "/importMongo.sh", $textFileSh); file_put_contents("../../modules/cityData/importData/importAllMongo.sh", $textImportMongoAll); if (isset($post['jsonImport'])) { $arrayDataImport = json_decode($post['jsonImport'], true); foreach ($arrayDataImport as $key => $value) { $newOrganization = Organization::newOrganizationFromImportData($value); try { $resData[] = Organization::insert($newOrganization, Yii::app()->session["userId"]); } catch (CTKException $e) { $resData[] = $e->getMessage(); } } $params = array("result" => true, "resData" => $resData); } else { $params = array("result" => false); } return $params; }
// $vOrganizationCode = $generalobj->UniqueID("ORG",PRJ_DB_PREFIX."_organization_master","vOrganizationCode",$charlimit="10"); $vOrganizationCode = $orgObj->getUniqueCode($Data['eOrganizationType']); // echo $vOrganizationCode; exit; $code = $Data['vOrganizationCode'] = $vOrganizationCode; // $vCompanyRegNo = $generalobj->UniqueID("",PRJ_DB_PREFIX."_organization_master","vCompanyRegNo",$charlimit="10"); $regno = $Data['vCompanyRegNo']; // = $vCompanyRegNo; $compcode = $Data['vCompCode']; // if(count($arr)>0) { $Data['eStatus'] = "Need to Verify"; /*} else { $Data['eStatus'] = "Active"; }*/ // prints($Data);exit; $orgObj->setAllVar($Data); $iOrganizationID = $res = $orgObj->insert(); //INSERT THIS RECORD IN ORGANIZATION_MASTER_TOVERIFY TABLE $insID = $gdbobj->getMaxId(PRJ_DB_PREFIX . "_organization_master", 'iOrganizationID'); $Data1 = $Data; $iOrganizationID = $Data1['iOrganizationID'] = $insID[0]['id']; $orgvrfObj->setAllVar($Data1); $res = $orgvrfObj->insert(); /* if($res){ $orgdtls = $orgObj->select($iOrganizationID); if($orgdtls[0]['eOrganizationType'] == 'Supplier'){ $opdt['vOrderStatusLevel'] = ''; $rs = $orgprefObj->updateData($opdt,"iOrganizationID=$iOrganizationID"); } else if($orgdtls[0]['eOrganizationType'] == 'Buyer'){ $opdt['vInvoiceStatusLevel'] = ''; $rs = $orgprefObj->updateData($opdt,"iOrganizationID=$iOrganizationID"); }
/** * function to map organization to contact while importing * checks if the organization already exists else add a new one * @param string $organization_name * @param object $import_object * @param array $data * @return integer idorganization */ public function map_contact_organization($organization_name, $import_object, $data) { $qry = "\n\t\tselect idorganization \n\t\tfrom organization \n\t\twhere organization_name = ?\n\t\tAND deleted = 0\n\t\tAND iduser ="******"do_user"]->iduser; $stmt = $this->getDbConnection()->executeQuery($qry, array(trim($organization_name))); if ($stmt->rowCount() > 0) { $rs = $stmt->fetch(); return $rs["idorganization"]; } else { if (strlen($organization_name) > 2) { $mapped_fields = $import_object->get_mapped_fields(); $do_organization = new Organization(); $do_organization->insert("organization", array("organization_name" => CommonUtils::purify_input($organization_name), "iduser" => $_SESSION["do_user"]->iduser)); $idorganization = $do_organization->getInsertId(); $q_upd = "\n\t\t\t\tupdate `organization`\n\t\t\t\tset `added_on` = ?\n\t\t\t\twhere `idorganization` = ?"; $do_organization->query($q_upd, array(date("Y-m-d H:i:s"), $idorganization)); $do_organization->insert("organization_custom_fld", array("idorganization" => $idorganization)); $mapped_fields = $import_object->get_mapped_fields(); if (array_search("cnt_mail_street", $mapped_fields) !== false) { $org_bill_address = $data[array_search("cnt_mail_street", $mapped_fields)]; } else { $org_bill_address = ''; } if (array_search("cnt_mail_pobox", $mapped_fields) !== false) { $org_bill_pobox = $data[array_search("cnt_mail_pobox", $mapped_fields)]; } else { $org_bill_pobox = ''; } if (array_search("cnt_mailing_city", $mapped_fields) !== false) { $org_bill_city = $data[array_search("cnt_mailing_city", $mapped_fields)]; } else { $org_bill_city = ''; } if (array_search("cnt_mailing_state", $mapped_fields) !== false) { $org_bill_state = $data[array_search("cnt_mailing_state", $mapped_fields)]; } else { $org_bill_state = ''; } if (array_search("cnt_mailing_postalcode", $mapped_fields) !== false) { $org_bill_postalcode = $data[array_search("cnt_mailing_postalcode", $mapped_fields)]; } else { $org_bill_postalcode = ''; } if (array_search("cnt_mailing_country", $mapped_fields) !== false) { $org_bill_country = $data[array_search("cnt_mailing_country", $mapped_fields)]; } else { $org_bill_country = ''; } $do_organization->insert("organization_address", array("idorganization" => $idorganization, "org_bill_address" => CommonUtils::purify_input($org_bill_address), "org_bill_pobox" => CommonUtils::purify_input($org_bill_pobox), "org_bill_city" => CommonUtils::purify_input($org_bill_city), "org_bill_state" => CommonUtils::purify_input($org_bill_state), "org_bill_postalcode" => CommonUtils::purify_input($org_bill_postalcode), "org_bill_country" => CommonUtils::purify_input($org_bill_country))); $do_data_history = new DataHistory(); $do_data_history->add_history($idorganization, 6, 'add'); $do_data_history->free(); return $idorganization; } else { return 0; } } }
/** * test putting a valid organization into the API */ public function testValidPut() { //create a new organization, and insert into the database $organization = new Organization(null, $this->VALID_ADDRESS1, $this->VALID_ADDRESS2, $this->VALID_CITY, $this->VALID_DESCRIPTION, $this->VALID_HOURS, $this->VALID_NAME, $this->VALID_PHONE, $this->VALID_STATE, $this->VALID_TYPE, $this->VALID_ZIP); $organization->insert($this->getPDO()); //update the organization $organization->setOrgName($this->VALID_NAME_ALT); //send the info to update to the API $response = $this->guzzle->put('https://bootcamp-coders.cnm.edu/~bbrown52/bread-basket/public_html/php/api/organization/' . $organization->getOrgId(), ['allow-redirects' => ['strict' => true], 'json' => $organization, 'headers' => ['X-XSRF-TOKEN' => $this->token]]); //ensure the response was sent, and the api returned a positive status $this->assertSame($response->getStatusCode(), 200); $body = $response->getBody(); $retrievedOrg = json_decode($body); $this->assertSame(200, $retrievedOrg->status); //pull the value from the DB, and make sure it was properly updated $neworg = Organization::getOrganizationByOrgId($this->getPDO(), $organization->getOrgId()); $this->assertSame($neworg->getOrgName(), $this->VALID_NAME_ALT); }