Example #1
0
function add_project()
{
    $project = array();
    $project['name'] = empty($_POST['name']) ? '' : $_POST['name'];
    $project['type'] = empty($_POST['type']) ? '' : $_POST['type'];
    $project['description'] = empty($_POST['description']) ? '' : $_POST['description'];
    $project['lng'] = empty($_POST['lng']) ? '' : $_POST['lng'];
    $project['lat'] = empty($_POST['lat']) ? '' : $_POST['lat'];
    $project['zoom'] = empty($_POST['zoom']) ? '' : $_POST['zoom'];
    $_project = new Project();
    $ret = $_project->add($project);
    if ($ret) {
        $response = "success";
    } else {
        $response = "failed";
    }
    echo $response;
}
Example #2
0
 function add()
 {
     parent::add();
 }
Example #3
0
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
* @since version 0.85
*/
include '../inc/includes.php';
if (empty($_GET["id"])) {
    $_GET["id"] = '';
}
Session::checkLoginUser();
$project = new Project();
if (isset($_POST["add"])) {
    $project->check(-1, CREATE, $_POST);
    $newID = $project->add($_POST);
    Event::log($newID, "project", 4, "maintain", sprintf(__('%1$s adds the item %2$s'), $_SESSION["glpiname"], $_POST["name"]));
    if ($_SESSION['glpibackcreated']) {
        Html::redirect($project->getFormURL() . "?id=" . $newID);
    } else {
        Html::back();
    }
} else {
    if (isset($_POST["delete"])) {
        $project->check($_POST["id"], DELETE);
        $project->delete($_POST);
        Event::log($_POST["id"], "project", 4, "maintain", sprintf(__('%s deletes an item'), $_SESSION["glpiname"]));
        $project->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $project->check($_POST["id"], DELETE);
Example #4
0
function addProjectWrapper()
{
    $name = Utils::getArrayValue($_POST, 'name');
    $identifier = Utils::getArrayValue($_POST, 'identifier');
    if (empty($identifier)) {
        $identifier = $name;
    }
    $parent_id = Utils::getArrayValue($_POST, 'parent_id');
    if (trim($identifier) === "") {
        $identifier = $name;
    }
    print json_encode(Project::add(App::getClient(), $name, $identifier, $parent_id));
    // TODO: inherit membership
    // $members = Project::getMembers(App::getClient(), 17);
    // echo "<PRE>";
    // print_r($members);
    // echo "<HR>";
    // $members = Project::getMembers(App::getClient(), 223);
    // print_r($members);
    // #$members = Project::addMembers(App::getClient(), 223, array('user_id'));
    // #print_r($members);
    // echo "<HR>";
    // $members = Project::getMembers(App::getClient(), 223);
    // print_r($members);
    // die;
}
Example #5
0
 /**
  * Event method to set a project on a task.
  * Get the last inserted id from the task and then check
  * if there is a project then add to project_task
  */
 function eventSetProjectTask(EventControler $evtcl)
 {
     $project_name = trim($evtcl->fields["project"]);
     $idtask = $evtcl->insertid;
     $q = new sqlQuery($this->getDbCon());
     if ($project_name != '') {
         $do_project = new Project();
         $do_project_task = new ProjectTask();
         $idproject = $do_project->getProjectIdByName($project_name);
         if ($idproject !== false) {
             $q->query("INSERT INTO project_task (idtask, idproject) VALUES (" . $idtask . ", " . $idproject . ")");
         } else {
             $do_project->addNew();
             $do_project->iduser = $_SESSION['do_User']->iduser;
             $do_project->name = $project_name;
             $do_project->status = 'open';
             $do_project->add();
             $idproject = $do_project->getPrimaryKeyValue();
             $q->query("INSERT INTO project_task (idtask, idproject) VALUES (" . $idtask . ", " . $idproject . ")");
         }
     }
 }
Example #6
0
function testsperengine()
{
    global $tests;
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "perform generic bean manipulation";
    $ok = 1;
    $bean = RedBean_OODB::dispense("note");
    $bean->message = "hai";
    $bean->color = 3;
    $bean->date = time();
    $bean->special = 'n';
    $bean->state = 90;
    RedBean_OODB::set($bean);
    $bean2 = RedBean_OODB::getById("note", 1);
    if ($bean2->state != 90 || $bean2->special != 'n' || $bean2->message != 'hai') {
        $ok = 0;
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bean->message = "lorem ipsum";
    RedBean_OODB::set($bean);
    $bean->message = 1;
    $bean->color = "green";
    $bean->date = str_repeat("BLABLA", 100);
    RedBean_OODB::set($bean);
    unset($bean);
    $bean = RedBean_OODB::dispense("note");
    $bean->color = "green";
    //print_r($bean);
    $bean3 = RedBean_OODB::find($bean, array("color" => "="));
    if (count($bean3) !== 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    unset($bean);
    $bean = RedBean_OODB::dispense("note");
    $bean->state = 80;
    $bean3 = RedBean_OODB::find($bean, array("state" => ">"));
    if (count($bean3) !== 1) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        $bla = RedBean_OODB::find($bean, array("undefined" => ">"));
    } catch (Exception $e) {
        //dont fail if prop does not exist
        die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $note = $bean3[1];
    $person = RedBean_OODB::dispense("person");
    $person->age = 50;
    $person->name = "Bob";
    $person->gender = "m";
    RedBean_OODB::set($person);
    RedBean_OODB::associate($person, $note);
    $memo = RedBean_OODB::getById("note", 1);
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) !== 1) {
        die("<b style='color:red'>Error CANNOT4:" . SmartTest::instance()->canwe);
    }
    RedBean_OODB::trash($authors[1]);
    //$ok=false;
    //try{
    $authors = RedBean_OODB::getAssoc($memo, "person");
    if (count($authors) > 0) {
        $ok = 0;
    }
    //}
    //catch(Exception $e){
    //	$ok=1;
    //}
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //unit tests
    //drop the note table
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "dispense an RedBean_OODB Bean";
    $oBean = RedBean_OODB::dispense();
    if (!$oBean instanceof OODBBean) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "put a bean in the database";
    $person = RedBean_OODB::dispense("person");
    $person->name = "John";
    $person->age = 35;
    $person->gender = "m";
    $person->hasJob = true;
    $id = RedBean_OODB::set($person);
    $johnid = $id;
    //echo "--->$id";
    $person2 = RedBean_OODB::getById("person", $id);
    if ($person2->age != $person->age) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $person2->anotherprop = 2;
    RedBean_OODB::set($person2);
    $person = RedBean_OODB::dispense("person");
    $person->name = "Bob";
    $person->age = 50;
    $person->gender = "m";
    $person->hasJob = false;
    $bobid = RedBean_OODB::set($person);
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "find records on basis of similarity";
    //RedBean_OODB::closeAllBeansOfType("person");
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->gender = "m";
    $persons = RedBean_OODB::find($searchBean, array("gender" => "="));
    if (count($persons) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //RedBean_OODB::closeAllBeansOfType("person");
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->name = "John";
    $persons = RedBean_OODB::find($searchBean, array("name" => "LIKE"));
    if (count($persons) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $searchBean2 = RedBean_OODB::dispense("person");
    $searchBean2->name = "John";
    $searchBean2->gender = "m";
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="));
    if (count($persons2) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //test limits (start end etc..)
    $searchBean2 = RedBean_OODB::dispense("person");
    $searchBean2->name = "John";
    $searchBean2->gender = "m";
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 1);
    if (count($persons2) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1);
    if (count($persons2) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1, "age ASC");
    if (count($persons2) == 1) {
        $who = array_pop($persons2);
        if ($who->name != "John") {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1, "age DESC");
    if (count($persons2) == 1) {
        $who = array_pop($persons2);
        if ($who->name != "Bob") {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //test extra sql
    $persons2 = RedBean_OODB::find($searchBean2, array("gender" => "="), 0, 1, "age DESC", "order by age ASC limit 1");
    if (count($persons2) == 1) {
        $who = array_pop($persons2);
        if ($who->name != "John") {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->age = "20";
    $searchBean->gender = "m";
    $persons = RedBean_OODB::find($searchBean, array("age" => ">"));
    if (count($persons) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->age = "20";
    $searchBean->gender = "v";
    $persons = RedBean_OODB::find($searchBean, array("age" => ">", "gender" => "="));
    if (count($persons) != 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $searchBean = RedBean_OODB::dispense("person");
    $searchBean->age = "50";
    $searchBean->name = "Bob";
    $searchBean->gender = "m";
    $persons = RedBean_OODB::find($searchBean, array("age" => "=", "name" => "LIKE", "gender" => "="));
    if (count($persons) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $whisky = RedBean_OODB::dispense("whisky");
    $whisky->name = "Glen Old";
    $whisky->age = 50;
    RedBean_OODB::set($whisky);
    $searchBean = RedBean_OODB::dispense("whisky");
    $searchBean->age = "12";
    $drinks = RedBean_OODB::find($searchBean, array("age" => ">"));
    if (count($drinks) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "associate beans with eachother?";
    $app = RedBean_OODB::dispense("appointment");
    $app->kind = "dentist";
    RedBean_OODB::set($app);
    RedBean_OODB::associate($person2, $app);
    $appforbob = array_shift(RedBean_OODB::getAssoc($person2, "appointment"));
    if (!$appforbob || $appforbob->kind != "dentist") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "delete a bean?";
    $person = RedBean_OODB::getById("person", $bobid);
    RedBean_OODB::trash($person);
    try {
        $person = RedBean_OODB::getById("person", $bobid);
        $ok = 0;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = true;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "unassociate two beans?";
    $john = RedBean_OODB::getById("person", $johnid);
    //hmmmmmm gaat mis bij innodb
    /*
    	SELECT * FROM `person` WHERE id = 2
    	Fatal error: Uncaught exception 'ExceptionFailedAccessBean' with message 'bean not found' in /Applications/xampp/xamppfiles/htdocs/cms/oodb.php:1161 Stack trace: #0 /Applications/xampp/xamppfiles/htdocs/cms/test.php(275): RedBean_OODB::getById('person', 2) #1 {main} thrown in /Applications/xampp/xamppfiles/htdocs/cms/oodb.php on line 1161
    */
    $app = RedBean_OODB::getById("appointment", 1);
    RedBean_OODB::unassociate($john, $app);
    $john2 = RedBean_OODB::getById("person", $johnid);
    $appsforjohn = RedBean_OODB::getAssoc($john2, "appointment");
    if (count($appsforjohn) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "unassociate by deleting a bean?";
    $anotherdrink = RedBean_OODB::dispense("whisky");
    $anotherdrink->name = "bowmore";
    $anotherdrink->age = 18;
    $anotherdrink->singlemalt = 'y';
    RedBean_OODB::set($anotherdrink);
    RedBean_OODB::associate($anotherdrink, $john);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    RedBean_OODB::trash($anotherdrink);
    $hisdrinks = RedBean_OODB::getAssoc($john, "whisky");
    if (count($hisdrinks) !== 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "create parent child relationships?";
    $pete = RedBean_OODB::dispense("person");
    $pete->age = 48;
    $pete->gender = "m";
    $pete->name = "Pete";
    $peteid = RedBean_OODB::set($pete);
    $rob = RedBean_OODB::dispense("person");
    $rob->age = 19;
    $rob->name = "Rob";
    $rob->gender = "m";
    $saskia = RedBean_OODB::dispense("person");
    $saskia->age = 20;
    $saskia->name = "Saskia";
    $saskia->gender = "f";
    RedBean_OODB::set($saskia);
    RedBean_OODB::set($rob);
    RedBean_OODB::addChild($pete, $rob);
    RedBean_OODB::addChild($pete, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $names = 0;
    if (is_array($children) && count($children) === 2) {
        foreach ($children as $child) {
            if ($child->name === "Rob") {
                $names++;
            }
            if ($child->name === "Saskia") {
                $names++;
            }
        }
    }
    if (!$names) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    $daddies = RedBean_OODB::getParent($saskia);
    $daddy = array_pop($daddies);
    if ($daddy->name === "Pete") {
        $ok = 1;
    } else {
        $ok = 0;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "remove a child from a parent-child tree?";
    RedBean_OODB::removeChild($daddy, $saskia);
    $children = RedBean_OODB::getChildren($pete);
    $ok = 0;
    if (count($children) === 1) {
        $only = array_pop($children);
        if ($only->name === "Rob") {
            $ok = 1;
        }
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //test exceptions
    $ok = 0;
    try {
        RedBean_OODB::addChild($daddy, $whisky);
    } catch (ExceptionInvalidParentChildCombination $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $ok = 0;
    try {
        RedBean_OODB::removeChild($daddy, $whisky);
    } catch (ExceptionInvalidParentChildCombination $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "save on the fly while associating?";
    $food = RedBean_OODB::dispense("dish");
    $food->name = "pizza";
    RedBean_OODB::associate($food, $pete);
    $petesfood = RedBean_OODB::getAssoc($pete, "food");
    if (is_array($petesfood) && count($petesfood) === 1) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //some extra tests... quick without further notice.
    $food = RedBean_OODB::dispense("dish");
    $food->name = "spaghetti";
    RedBean_OODB::trash($food);
    //test aggregation functions
    //insert stat table
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 1;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 2;
    RedBean_OODB::set($s);
    $s = RedBean_OODB::dispense("stattest");
    $s->amount = 3;
    RedBean_OODB::set($s);
    SmartTest::instance()->canwe = "can we use aggr functions using Redbean?";
    if (RedBean_OODB::numberof("stattest") != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::maxof("stattest", "amount") != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::minof("stattest", "amount") != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::avgof("stattest", "amount") != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::sumof("stattest", "amount") != 6) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::distinct("stattest", "amount")) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //test list function
    SmartTest::instance()->canwe = "can we use list functions using Redbean?";
    if (count(RedBean_OODB::listAll("stattest")) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1)) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1, 1)) != 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1, 2)) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count(RedBean_OODB::listAll("stattest", 1, 1, "", " limit 100 ")) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //now test with decorator =======================================
    RedBean_OODB::setLocking(true);
    $i = 3;
    SmartTest::instance()->canwe = "generate only valid classes?";
    try {
        $i += RedBean_OODB::gen("");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //nothing
    try {
        $i += RedBean_OODB::gen(".");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen(",");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //illegal chars
    try {
        $i += RedBean_OODB::gen("null");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //keywords
    try {
        $i += RedBean_OODB::gen("Exception");
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //reserved
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "generate classes using Redbean?";
    if (!class_exists("Bug")) {
        $i += RedBean_OODB::gen("Bug");
        if ($i !== 4) {
            die("<b style='color:red'>Error CANNOT {$i}:" . SmartTest::instance()->canwe);
        }
    } else {
        if ($i !== 3) {
            die("<b style='color:red'>Error CANNOT {$i}:" . SmartTest::instance()->canwe);
        }
    }
    if (!class_exists("Bug")) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "use getters and setters";
    $bug = new Bug();
    $bug->setSomething(sha1("abc"));
    if ($bug->getSomething() != sha1("abc")) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //can we use non existing props? --triggers fatal..
    $bug->getHappy();
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "use oget and oset?";
    RedBean_OODB::gen("Project");
    $proj = new Project();
    $proj->setName("zomaar");
    $bug->osetProject($proj);
    $bug->save();
    $oldbug = new Bug(1);
    $oldproj = $oldbug->ogetProject();
    if ($oldproj->getName() != "zomaar") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "Use boolean values and retrieve them with is()?";
    if ($bug->isHappy()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bug->setHappy(true);
    $bug->save();
    $bug = new Bug(1);
    if (!$bug->isHappy()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bug->setHappy(false);
    if ($bug->isHappy()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "break oget/oset assoc?";
    $bug->osetProject(null);
    $bug->save();
    $bug = null;
    $bug = new Bug(1);
    $proj = $bug->ogetProject();
    if ($proj->getID() > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "Use the decorator to associate items?";
    $bug = null;
    $bug1 = new Bug();
    $bug2 = new Bug();
    $bug1->setName("b1");
    $bug2->setName("b2");
    $p = new Project();
    $p->setProjectNum(42);
    $p->add($bug1);
    $p->add($bug2);
    $p = null;
    $b = new Project();
    $b->setProjectNum(42);
    //also fck up case...
    $arr = RedBean_Decorator::find($b, array("PRoJECTnuM" => "="));
    $proj = array_pop($arr);
    $bugs = $proj->getRelatedBug();
    if (count($bugs) !== 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "use hierarchies?";
    $sub1 = new Project();
    $sub2 = new Project();
    $sub3 = new Project();
    $sub1->setName("a");
    $sub2->setName("b");
    $sub2->setDate(time());
    $sub3->setName("c");
    $sub2->attach($sub3);
    $proj->attach($sub1)->attach($sub2);
    $arr = RedBean_Decorator::find($b, array("PRoJECTnuM" => "="));
    $proj = array_pop($arr);
    $c = $proj->children();
    foreach ($c as $c1) {
        if ($c1->getName() == "b") {
            break;
        }
    }
    $c2 = $c1->children();
    $sub3 = array_pop($c2);
    if ($sub3->getName() != "c") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "make our own models";
    if (!class_exists("Customer")) {
        class Customer extends RedBean_Decorator
        {
            public function __construct($id = 0)
            {
                parent::__construct("Customer", $id);
            }
            //each customer may only have one project
            public function setProject(Project $project)
            {
                $this->clearRelatedProject();
                $this->command("add", array($project));
            }
            public function add($what)
            {
                if ($what instanceof Project) {
                    return false;
                }
                $this->command("add", array($what));
            }
        }
    }
    $p2 = new Project();
    $p2->setName("hihi");
    $cust = new Customer();
    $cust->setProject($p2);
    $cust->add($p2);
    $cust->setProject($proj);
    $ps = $cust->getRelatedProject();
    if (count($ps) > 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $p = array_pop($ps);
    if ($p->getName() == "hihi") {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "delete all assoc";
    $cust->clearAllRelations();
    $ps = $cust->getRelatedProject();
    if (count($ps) > 0) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "not mess with redbean";
    $bla = new Customer();
    Redbean_Decorator::find($bla, array());
    $ok = 0;
    try {
        Redbean_Decorator::find($bla, array("bkaa" => "q="));
    } catch (ExceptionInvalidFindOperator $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "manipulate hierarchies";
    $cust2 = new Customer();
    $cust->attach($cust2);
    $c = $cust->children();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $cust->remove($cust2);
    $c = $cust->children();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust->attach($cust2);
    Customer::delete($cust2);
    $c = $cust->children();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "remove associations";
    $cust3 = new Customer();
    $cust4 = new Customer();
    $cust3->add($cust4);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT1:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust3->remove($cust4);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust3 = new Customer();
    $cust4 = new Customer();
    $cust3->add($cust4);
    $cust3->add($cust4);
    //also test multiple assoc
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust4->remove($cust3);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT4:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    $cust3 = new Customer();
    $cust4 = new Customer();
    $cust3->add($cust4);
    $cust3->add($cust4);
    //also test multiple assoc
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 1) {
        die("<b style='color:red'>Error CANNOT5:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    Customer::delete($cust4);
    $c = $cust3->getRelatedCustomer();
    if (count($c) !== 0) {
        die("<b style='color:red'>Error CANNOT6:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "import from post";
    $_POST["hallo"] = 123;
    $_POST["there"] = 456;
    $_POST["nope"] = 789;
    $cust = new Customer();
    $cust->importFromPost(array("hallo", "there"));
    if ($cust->getHallo() == 123 && $cust->getThere() == 456 && !$cust->getNope()) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        exit;
    }
    foreach ($cust->problems() as $p) {
        if ($p) {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    }
    SmartTest::instance()->progress();
    $_POST["hallo"] = 123;
    $_POST["there"] = 456;
    $_POST["nope"] = 789;
    $cust = new Customer();
    $cust->importFromPost("hallo,there");
    if ($cust->getHallo() == 123 && $cust->getThere() == 456 && !$cust->getNope()) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
        exit;
    }
    foreach ($cust->problems() as $p) {
        if ($p) {
            die("<b style='color:red'>Error CANNOT3:" . SmartTest::instance()->canwe);
        }
    }
    SmartTest::instance()->progress();
    $_POST["hallo"] = 123;
    $_POST["there"] = 456;
    $_POST["nope"] = 789;
    $cust = new Customer();
    $cust->importFromPost();
    if ($cust->getHallo() == 123 && $cust->getThere() == 456 && $cust->getNope()) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        exit;
    }
    foreach ($cust->problems() as $p) {
        if ($p) {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
    }
    SmartTest::instance()->progress();
    if (!class_exists("Trick")) {
        class Trick extends RedBean_Decorator
        {
            public function __construct($id = 0)
            {
                parent::__construct("Customer", $id);
            }
            public function setHallo()
            {
                return "hallodaar";
            }
        }
    }
    $trick = new Trick();
    $trick->importFromPost(array("hallo", "there"));
    $message = array_shift($trick->problems());
    if ($message === "hallodaar") {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        exit;
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "avoid race-conditions by locking?";
    RedBean_OODB::gen("Cheese,Wine");
    $cheese = new Cheese();
    $cheese->setName('Brie');
    $cheese->save();
    $cheese = new Cheese(1);
    //try to mess with the locking system...
    $oldkey = RedBean_OODB::$pkey;
    RedBean_OODB::$pkey = 1234;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $bordeaux = new Wine();
    $bordeaux->setRegion("Bordeaux");
    try {
        $bordeaux->add($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->attach($cheese);
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 1;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        $bordeaux->add(new Wine());
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    RedBean_OODB::$pkey = $oldkey;
    $cheese = new Cheese(1);
    $cheese->setName("Camembert");
    $ok = 0;
    try {
        $cheese->save();
        $ok = 1;
    } catch (ExceptionFailedAccessBean $e) {
        $ok = 0;
    }
    if (!$ok) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        RedBean_OODB::$pkey = 999;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    try {
        RedBean_OODB::$pkey = 123;
        RedBean_OODB::setLockingTime(100);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar2");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        die("<b style='color:red'>Error CANNOT-C:" . SmartTest::instance()->canwe);
    } catch (Exception $e) {
        SmartTest::instance()->progress();
    }
    try {
        RedBean_OODB::$pkey = 42;
        RedBean_OODB::setLockingTime(0);
        $cheese = new Cheese(1);
        $cheese->setName("Cheddar3");
        $cheese->save();
        RedBean_OODB::setLockingTime(10);
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    //test value ranges
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(-1);
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(1.5);
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime("aaa");
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "protect inner state of RedBean";
    try {
        RedBean_OODB::setLockingTime(null);
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } catch (ExceptionInvalidArgument $e) {
    }
    SmartTest::instance()->progress();
    //can we reset logs
    SmartTest::instance()->canwe = "reset the logs?";
    $logs = RedBean_DBAdapter::getLogs();
    //are the logs working?
    if (is_array($logs) && count($logs) > 0) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    RedBean_DBAdapter::resetLogs();
    $logs = RedBean_DBAdapter::getLogs();
    if (is_array($logs) && count($logs) === 0) {
        SmartTest::instance()->progress();
    } else {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    SmartTest::instance()->canwe = "freeze the database?";
    RedBean_OODB::freeze();
    $joop = new Project();
    $joop->setName("Joop");
    $joopid = $joop->save();
    if (!is_numeric($joopid) || $joopid < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $joop->setBlaaataap("toppiedoe");
    $joop->save();
    $joop2 = new Project($joopid);
    $name = $joop2->getName();
    $blaataap = $joop2->getBlaataap();
    if ($name !== "Joop") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (!is_null($blaataap)) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    try {
        RedBean_OODB::gen("haas");
        $haas = new Haas();
        $haas->setHat("redhat");
        $id = $haas->save();
        if ($id !== 0) {
            die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
        }
        SmartTest::instance()->progress();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    $cheese = new Cheese();
    $cheese->setName("bluecheese");
    $cheeseid = $cheese->save();
    if (!$cheeseid) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    $anothercheese = new Cheese();
    $cheese->add($anothercheese);
    $cheese->attach($anothercheese);
    $a1 = $cheese->getRelatedCheese();
    $a2 = $cheese->children();
    if (!is_array($a1) || is_array($a1) && count($a1) !== 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (!is_array($a2) || is_array($a2) && count($a2) !== 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //now scan the logs for database modifications
    $logs = strtolower(implode(",", RedBean_DBAdapter::getLogs()));
    if (strpos("alter", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("truncate", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("drop", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("change", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("show", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("describe", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    if (strpos("drop database", $logs) !== false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //should be unable to do gc() and optimize() and clean() and resetAll()
    RedBean_DBAdapter::resetLogs();
    if (RedBean_OODB::gc() && count(RedBean_DBAdapter::getLogs()) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::optimizeIndexes() && count(RedBean_DBAdapter::getLogs()) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::clean() && count(RedBean_DBAdapter::getLogs()) > 0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::registerUpdate("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (RedBean_OODB::registerSearch("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "can we unfreeze the database";
    try {
        RedBean_OODB::unfreeze();
    } catch (Exception $e) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    }
    SmartTest::instance()->progress();
    //should be ABLE to do gc() and optimize() and clean() and resetAll()
    RedBean_DBAdapter::resetLogs();
    if (!RedBean_OODB::gc() && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::optimizeIndexes() && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::clean() && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::registerUpdate("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (!RedBean_OODB::registerSearch("cheese") && count(RedBean_DBAdapter::getLogs()) < 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //test convenient tree functions
    SmartTest::instance()->canwe = "convient tree functions";
    if (!class_exists("Person")) {
        RedBean_OODB::gen("person");
    }
    $donald = new Person();
    $donald->setName("Donald");
    $donald->save();
    $kwik = new Person();
    $kwik->setName("Kwik");
    $kwik->save();
    $kwek = new Person();
    $kwek->setName("Kwek");
    $kwek->save();
    $kwak = new Person();
    $kwak->setName("Kwak");
    $kwak->save();
    $donald->attach($kwik);
    $donald->attach($kwek);
    $donald->attach($kwak);
    if (count($donald->children()) != 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if (count($kwik->siblings()) != 2) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //todo
    if ($kwik->hasParent($donald) != true) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasParent($kwak) != false) {
        die("<b style='color:red'>Error CANNOT2:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($kwak) != true) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($donald->hasChild($donald) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasChild($kwik) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwek) != true) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($kwak) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($kwak->hasSibling($donald) != false) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    //copy
    SmartTest::instance()->canwe = "copy functions";
    $kwak2 = $kwak->copy();
    $id = $kwak2->save();
    $kwak2 = new Person($id);
    if ($kwak->getName() != $kwak2->getName()) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "countRelated";
    R::gen("Blog,Comment");
    $blog = new Blog();
    $blog2 = new Blog();
    $blog->setTitle("blog1");
    $blog2->setTitle("blog2");
    for ($i = 0; $i < 5; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog->add($comment);
    }
    for ($i = 0; $i < 3; $i++) {
        $comment = new Comment();
        $comment->setText("comment no.  {$i} ");
        $blog2->add($comment);
    }
    if ($blog->numofComment() !== 5) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    if ($blog2->numofComment() !== 3) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "associate tables of the same name";
    $blog = new Blog();
    $blogb = new Blog();
    $blog->title = 'blog a';
    $blogb->title = 'blog b';
    $blog->add($blogb);
    $b = $blog->getRelatedBlog();
    if (count($b) !== 1) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $b = array_pop($b);
    if ($b->title != 'blog b') {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "inferTypeII patch";
    $blog->rating = 4294967295.0;
    $blog->save();
    $id = $blog->getID();
    $blog2->rating = -1;
    $blog2->save();
    $blog = new Blog($id);
    if ($blog->getRating() != 4294967295.0) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    SmartTest::instance()->canwe = "Longtext column type";
    $blog->message = str_repeat("x", 65535);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65535) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "text") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $blog->message = str_repeat("x", 65536);
    $blog->save();
    $blog = new Blog($id);
    if (strlen($blog->message) != 65536) {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    $rows = RedBean_OODB::$db->get("describe blog");
    if ($rows[3]["Type"] != "longtext") {
        die("<b style='color:red'>Error CANNOT:" . SmartTest::instance()->canwe);
    } else {
        SmartTest::instance()->progress();
    }
    Redbean_OODB::clean();
}
Example #7
0
<?php

include "threephp/THREE.php";
include "tpl/inc/board.php";
include "tpl/inc/street.php";
include "tpl/inc/bank.php";
include "tpl/inc/house.php";
include "tpl/inc/pawn.php";
include "tpl/inc/dice.php";
include "tpl/inc/game.php";
include "tpl/inc/logo.php";
include "tpl/inc/dialog.php";
$project = new Project(null, '{ "name":"Example" }');
$page = new Page($project, '{ "name":"Main", "file":"tpl/index.php", "path":"index" }');
$project->add($page);
$scene = new Scene($page, '{ "resize":"true", "stat":"true", "click":"true", "info":"true", "control":"true", "tween":"true", "physics":"true" }');
$page->add($scene);
$scene->add(new Bank($scene, '{ "amount": 24500000 }'));
$page->add(new Console($page, '{}'));
$board = new Board($scene, '{}');
$scene->add($board);
$scene->add(new Game($scene, '{}'));
$board->add(new Street($board, '{ "x":-406, "z":406, "label":"Start" }'));
$board->add(new Street($board, '{ "x":-406, "z":203, "rotation":' . (0 - M_PI / 2) . ', "label":"Business Park", "type":"Bedrijfspand", "city":"Vught", "cost":1500000, "profit":12250000 }'));
$board->add(new Street($board, '{ "x":-406, "z":0, "rotation":' . (0 - M_PI / 2) . ', "label":"Koningsweg", "type":"Kantoor", "city":"\'s-Hertogenbosch", "cost":2000000, "profit":13750000 }'));
$board->add(new Street($board, '{ "x":-406, "z":-203, "rotation":' . (0 - M_PI / 2) . ', "label":"Hooge Steenweg", "type":"Winkels en woningen", "city":"\'s-Hertogenbosch", "cost":3000000, "profit":15000000 }'));
$board->add(new Street($board, '{ "x":-406, "z":-406, "label":"Op bezoek" }'));
$board->add(new Street($board, '{ "x":-203, "z":-406, "rotation":' . (0 - M_PI) . ', "label":"Noble", "type":"Restaurant", "city":"\'s-Hertogenbosch", "cost":3000000, "profit":17500000 }'));
$board->add(new Street($board, '{ "x":0, "z":-406, "rotation":' . (0 - M_PI) . ', "label":"Schapenmarkt", "type":"Winkels", "city":"\'s-Hertogenbosch", "cost":4000000, "profit":20000000 }'));
$board->add(new Street($board, '{ "x":203, "z":-406, "rotation":' . (0 - M_PI) . ', "label":"Kerkstraat", "type":"Winkels", "city":"\'s-Hertogenbosch", "cost":4500000, "profit":21500000 }'));
$board->add(new Street($board, '{ "x":406, "z":-406, "label":"Vrij parkeren" }'));
Example #8
0
 public function add()
 {
     //Subject,Type,CreateTime,PublishTime,Status,UserId,Department,Team,Hours,Developer,Schedule,Detail,Pv,Uv,Fans,Summary,Laud
     $res = array();
     $project = new Project();
     $project->Subject = $this->Subject;
     $project->Detail = $this->Detail;
     $project->Type = $this->Type;
     $project->CreateTime = date('Y-m-d H:i:s');
     $project->PublishTime = $this->PublishTime;
     $project->Status = 1;
     $project->UserId = $_SESSION['userid'];
     $project->Department = $this->Department;
     $project->Team = $this->Team;
     $project->Hours = 0;
     $project->Developer = '';
     $project->Schedule = 0;
     $project->Pv = 0;
     $project->Uv = 0;
     $project->Fans = 0;
     $project->Summary = '';
     $project->Laud = 0;
     $result = $project->add();
     if ($result > 0) {
         $res['Success'] = true;
         $res['Message'] = "需求提交成功";
         $res['NewId'] = $result;
         //发送部门老大emailt通知
         $user = new User();
         $userMode = $user->getVerifyer($project->Department);
         $res['Email'] = $userMode['Email'];
         if (!empty($userMode['Email'])) {
             $mail = new SaeMail();
             $verifyUrl = URL_WEBSITE . "/basic/project_detail.php?id=" . $result . "&selected=2";
             $res['Email'] = $userMode['Email'];
             //发送邮件操作
             $keys = array();
             $keys['to'] = $userMode['Email'];
             if ($project->Department == 101) {
                 //大客户事业部需要抄送
                 $keys['cc'] = 'ericzhang@thindov.com,orien.young@thindov.com,endertan@thindov.com,sauwe@qq.com';
             }
             $keys['from'] = "*****@*****.**";
             $keys['smtp_port'] = "25";
             $keys['smtp_username'] = "******";
             $keys['smtp_password'] = "******";
             $mailsubject = "技术开发需求审核:" . $project->Subject;
             $mailbody = "Dear " . $userMode['Name'];
             $mailbody .= "<br />";
             $mailbody .= "<br />";
             $mailbody .= "您好,您的部门有新的技术开发需求,需要您审核。需求如下:";
             $mailbody .= "<br />";
             $mailbody .= "<br />";
             $mailbody .= "主题:" . $project->Subject;
             $mailbody .= "<br />";
             $mailbody .= "<br />";
             $mailbody .= "描述:" . $project->Detail;
             $mailbody .= "<br />";
             $mailbody .= "<br />";
             $mailbody .= "请点击以下链接进入审核:";
             $mailbody .= "<br />";
             $mailbody .= "<br />";
             $mailbody .= "<a href='" . $verifyUrl . "'>" . $verifyUrl . "</a>";
             $mailbody .= "<br />";
             $mailbody .= "<br />";
             $mailbody .= "——深圳尚道微营销有限公司  技术中心";
             $mailbody .= "<br />";
             $mailbody .= "<br />";
             $mailbody .= "该邮件由“技术开发管理平台”系统发出,无需回复。";
             $keys['subject'] = $mailsubject;
             $keys['content'] = $mailbody;
             $keys['content_type'] = 'HTML';
             $keys['smtp_host'] = "smtp.qq.com";
             $mail->setOpt($keys);
             $ret = $mail->send();
             //if ($ret === false)
             //var_dump($mail->errno(), $mail->errmsg());
             $mail->clean();
         }
     } else {
         $res['Success'] = false;
         $res['Message'] = "需求提交失败,请联系技术部";
     }
     echo json_encode($res);
     exit;
 }
 function eventImportAccount(EventControler $evtcl)
 {
     $msg = "";
     $uploaded_file = $_FILES['fields']['name']['import_account'];
     $target_path = 'files/' . $uploaded_file;
     if (!move_uploaded_file($_FILES['fields']['tmp_name']['import_account'], $target_path)) {
         $msg = "There was an error uploading the file, please try again!";
     } else {
         chmod($target_path, 0755);
         if (file_exists($target_path)) {
             //$xml = simplexml_load_file($_SERVER['DOCUMENT_ROOT']."/".$target_path);
             $str_xml = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/" . $target_path);
             $str_xml = preg_replace('/[^(\\x20-\\x7F)]*/', '', $str_xml);
             $xml = simplexml_load_string($str_xml);
             echo '<pre>';
             print_r($xml);
             echo '</pre>';
             die;
             if ($xml !== FALSE) {
                 $c_cnt = count($xml->contact);
                 if ($c_cnt) {
                     for ($i = 0; $i < $c_cnt; $i++) {
                         $do_contact = new Contact();
                         $contact = $xml->contact[$i];
                         $do_contact->firstname = $contact->firstname;
                         $do_contact->lastname = $contact->lastname;
                         $do_contact->position = $contact->position;
                         $do_contact->company = $contact->company;
                         $do_contact->idcompany = $contact->idcompany;
                         $do_contact->iduser = $_SESSION['do_User']->iduser;
                         $do_contact->picture = $contact->picture;
                         $do_contact->summary = $contact->summary;
                         $do_contact->birthday = $contact->birthday;
                         $do_contact->portal_code = $contact->portal_code;
                         $do_contact->fb_userid = $contact->fb_userid;
                         $do_contact->tw_user_id = $contact->tw_user_id;
                         $do_contact->email_optout = $contact->email_optout;
                         $do_contact->add();
                         $lastInsertedContId = $do_contact->getPrimaryKeyValue();
                         /**
                          *Contact Address	
                          */
                         $ca_cnt = count($contact->contact_address);
                         if ($ca_cnt) {
                             for ($ca_cnt_i = 0; $ca_cnt_i < $ca_cnt; $ca_cnt_i++) {
                                 $do_contact_address = new ContactAddress();
                                 $contact_address = $contact->contact_address[$ca_cnt_i];
                                 $do_contact_address->city = $contact_address->city;
                                 $do_contact_address->country = $contact_address->country;
                                 $do_contact_address->state = $contact_address->state;
                                 $do_contact_address->street = $contact_address->street;
                                 $do_contact_address->zipcode = $contact_address->zipcode;
                                 $do_contact_address->idcontact = $lastInsertedContId;
                                 $do_contact_address->address = $contact_address->address;
                                 $do_contact_address->address_type = $contact_address->address_type;
                                 $do_contact_address->add();
                                 $do_contact_address->free();
                             }
                         }
                         /**
                          *Contact Email	
                          */
                         $ce_cnt = count($contact->contact_email);
                         if ($ce_cnt) {
                             for ($ce_cnt_i = 0; $ce_cnt_i < $ce_cnt; $ce_cnt_i++) {
                                 $do_contact_email = new ContactEmail();
                                 $contact_email = $contact->contact_email[$ce_cnt_i];
                                 $do_contact_email->idcontact = $lastInsertedContId;
                                 $do_contact_email->email_address = $contact_email->email_address;
                                 $do_contact_email->email_type = $contact_email->email_type;
                                 $do_contact_email->email_isdefault = $contact_email->email_isdefault;
                                 $do_contact_email->add();
                                 $do_contact_email->free();
                             }
                         }
                         /**
                          *Contact Phone 
                          */
                         $cp_cnt = count($contact->contact_phone);
                         if ($cp_cnt) {
                             for ($cp_cnt_i = 0; $cp_cnt_i < $cp_cnt; $cp_cnt_i++) {
                                 $do_contact_phone = new ContactPhone();
                                 $contact_phone = $contact->contact_phone[$cp_cnt_i];
                                 $do_contact_phone->phone_number = $contact_phone->phone_number;
                                 $do_contact_phone->phone_type = $contact_phone->phone_type;
                                 $do_contact_phone->idcontact = $lastInsertedContId;
                                 $do_contact_phone->add();
                                 $do_contact_phone->free();
                             }
                         }
                         /**
                          *Contact Note	
                          */
                         $cn_cnt = count($contact->contact_note);
                         if ($cn_cnt) {
                             for ($cn_cnt_i = 0; $cn_cnt_i < $cn_cnt; $cn_cnt_i++) {
                                 $do_contact_note = new ContactNotes();
                                 $contact_note = $contact->contact_note[$cn_cnt_i];
                                 $do_contact_note->idcontact = $lastInsertedContId;
                                 $do_contact_note->note = $contact_note->note;
                                 $do_contact_note->date_added = $contact_note->date_added;
                                 $do_contact_note->document = $contact_note->document;
                                 $do_contact_note->idcompany = $contact_note->idcompany;
                                 $do_contact_note->iduser = $_SESSION['do_User']->iduser;
                                 $do_contact_note->priority = $contact_note->priority;
                                 $do_contact_note->send_email = $contact_note->send_email;
                                 $do_contact_note->hours_work = $contact_note->hours_work;
                                 $do_contact_note->note_visibility = $contact_note->note_visibility;
                                 $do_contact_note->type = $contact_note->type;
                                 $do_contact_note->add();
                                 $do_contact_note->free();
                             }
                         }
                         /**
                          *Contact Tag	
                          */
                         $ctag_cnt = count($contact->contact_tag);
                         if ($ctag_cnt) {
                             for ($ctag_cnt_i = 0; $ctag_cnt_i < $ctag_cnt; $ctag_cnt_i++) {
                                 $do_tag = new Tag();
                                 $contact_tag = $contact->contact_tag[$ctag_cnt_i];
                                 $do_tag->tag_name = $contact_tag->tag_name;
                                 $do_tag->iduser = $_SESSION['do_User']->iduser;
                                 $do_tag->reference_type = $contact_tag->reference_type;
                                 $do_tag->idreference = $lastInsertedContId;
                                 $do_tag->date_added = $contact_tag->date_added;
                                 $do_tag->add();
                                 $do_tag->free();
                             }
                         }
                         /**
                          *Contact tasks which are not associated with Project	
                          */
                         //Contact tasks which are not associated with Project
                         $ctwop_cnt = count($contact->contact_task_without_project);
                         if ($ctwop_cnt) {
                             for ($ctwop_cnt_i = 0; $ctwop_cnt_i < $ctwop_cnt; $ctwop_cnt_i++) {
                                 $do_task = new Task();
                                 $contact_task_wo_p = $contact->contact_task_without_project[$ctwop_cnt_i];
                                 $do_task->task_description = $contact_task_wo_p->task_description;
                                 $do_task->due_date = $contact_task_wo_p->due_date;
                                 $do_task->category = $contact_task_wo_p->category;
                                 $do_task->iduser = $_SESSION['do_User']->iduser;
                                 $do_task->due_date_dateformat = $contact_task_wo_p->due_date_dateformat;
                                 $do_task->status = $contact_task_wo_p->status;
                                 $do_task->date_completed = $contact_task_wo_p->date_completed;
                                 $do_task->idcontact = $lastInsertedContId;
                                 $do_task->from_note = $contact_task_wo_p->from_note;
                                 $do_task->is_sp_date_set = $contact_task_wo_p->is_sp_date_set;
                                 $do_task->task_category = $contact_task_wo_p->task_category;
                                 $do_task->add();
                                 $do_task->free();
                             }
                         }
                         /**
                          *Contact tasks which are associated with Project	
                          */
                         $arr_prj = array();
                         $cont_task_with_prj_cnt = count($contact->contact_task_with_project);
                         if ($cont_task_with_prj_cnt) {
                             for ($i = 0; $i < $cont_task_with_prj_cnt; $i++) {
                                 $do_project = new Project();
                                 $project = $contact->contact_task_with_project[$i];
                                 $do_project->iduser = $_SESSION['do_User']->iduser;
                                 $do_project->name = $project->name;
                                 $do_project->end_date_dateformat = $project->end_date_dateformat;
                                 $do_project->idcompany = $project->idcompany;
                                 $do_project->status = $project->status;
                                 $do_project->effort_estimated_hrs = $project->effort_estimated_hrs;
                                 $do_project->is_public = $project->is_public;
                                 $do_project->add();
                                 $lastInsertedPrjId = $do_project->getPrimaryKeyValue();
                                 //$arr_prj[$lastInsertedPrjId] = $project->idproject;
                                 $pt_cnt = count($project->project_task);
                                 if ($pt_cnt) {
                                     for ($pt_cnt_i = 0; $pt_cnt_i < $pt_cnt; $pt_cnt_i++) {
                                         $do_task = new Task();
                                         $project_task = $project->project_task[$pt_cnt_i];
                                         $do_task->task_description = $project_task->task_description;
                                         $do_task->due_date = $project_task->due_date;
                                         $do_task->category = $project_task->category;
                                         $do_task->iduser = $_SESSION['do_User']->iduser;
                                         $do_task->due_date_dateformat = $project_task->due_date_dateformat;
                                         $do_task->status = $project_task->status;
                                         $do_task->date_completed = $project_task->date_completed;
                                         $do_task->idcontact = $lastInsertedContId;
                                         $do_task->from_note = $project_task->from_note;
                                         $do_task->is_sp_date_set = $project_task->is_sp_date_set;
                                         $do_task->task_category = $project_task->task_category;
                                         $do_task->add();
                                         $lastInsertedTaskId = $do_task->getPrimaryKeyValue();
                                         $do_project_task = new ProjectTask();
                                         $do_project_task->idtask = $lastInsertedTaskId;
                                         $do_project_task->idproject = $lastInsertedPrjId;
                                         $do_project_task->progress = $project_task->progress;
                                         $do_project_task->drop_box_code = $project_task->drop_box_code;
                                         $do_project_task->priority = $project_task->priority;
                                         $do_project_task->hrs_work_expected = $project_task->hrs_work_expected;
                                         $do_project_task->add();
                                         $lastInsertedPrjTaskId = $do_project_task->getPrimaryKeyValue();
                                         $pd_cnt = count($project_task->project_discuss);
                                         if ($pd_cnt) {
                                             for ($i = 0; $i < $pd_cnt; $i++) {
                                                 $do_project_discuss = new ProjectDiscuss();
                                                 $project_discuss = $project_task->project_discuss[$i];
                                                 $do_project_discuss->idproject_task = $lastInsertedPrjTaskId;
                                                 $do_project_discuss->idtask = $lastInsertedTaskId;
                                                 $do_project_discuss->idproject = $lastInsertedPrjId;
                                                 $do_project_discuss->discuss = $project_discuss->discuss;
                                                 $do_project_discuss->date_added = $project_discuss->date_added;
                                                 $do_project_discuss->document = $project_discuss->document;
                                                 $do_project_discuss->iduser = $_SESSION['do_User']->iduser;
                                                 $do_project_discuss->drop_box_sender = $project_discuss->drop_box_sender;
                                                 $do_project_discuss->priority = $project_discuss->priority;
                                                 $do_project_discuss->hours_work = $project_discuss->hours_work;
                                                 $do_project_discuss->discuss_edit_access = $project_discuss->discuss_edit_access;
                                                 $do_project_discuss->type = $project_discuss->type;
                                                 $do_project_discuss->add();
                                                 $do_project_discuss->free();
                                             }
                                         }
                                         $do_project_task->free();
                                         $do_task->free();
                                     }
                                 }
                                 $do_project->free();
                             }
                         }
                         /**
                          *Invoice import
                          */
                         $msg_inv = "";
                         $inv_cnt = count($contact->invoice);
                         if ($inv_cnt) {
                             for ($inv_cnt_i = 0; $inv_cnt_i < $inv_cnt; $inv_cnt_i++) {
                                 $do_invoice = new Invoice();
                                 $invoice = $contact->invoice[$inv_cnt_i];
                                 $do_invoice->num = $invoice->num;
                                 $do_invoice->iduser = $_SESSION['do_User']->iduser;
                                 $do_invoice->description = $invoice->description;
                                 $do_invoice->amount = $invoice->amount;
                                 $do_invoice->datepaid = $invoice->datepaid;
                                 $do_invoice->datecreated = $invoice->datecreated;
                                 $do_invoice->status = $invoice->status;
                                 $do_invoice->discount = $invoice->discount;
                                 $do_invoice->idcontact = $lastInsertedContId;
                                 $do_invoice->due_date = $invoice->due_date;
                                 $do_invoice->invoice_address = $invoice->invoice_address;
                                 $do_invoice->invoice_term = $invoice->invoice_term;
                                 $do_invoice->invoice_note = $invoice->invoice_note;
                                 $do_invoice->sub_total = $invoice->sub_total;
                                 $do_invoice->net_total = $invoice->net_total;
                                 $do_invoice->amt_due = $invoice->amt_due;
                                 $do_invoice->idcompany = $invoice->idcompany;
                                 $do_invoice->tax = $invoice->tax;
                                 $do_invoice->set_delete = $invoice->set_delete;
                                 $do_invoice->total_discounted_amt = $invoice->total_discounted_amt;
                                 $do_invoice->total_taxed_amount = $invoice->total_taxed_amount;
                                 $do_invoice->add();
                                 $lastInsertedInvoiceId = $do_invoice->getPrimaryKeyValue();
                                 $invline_cnt = count($invoice->invoiceline);
                                 if ($invline_cnt) {
                                     for ($invline_cnt_i = 0; $invline_cnt_i < $invline_cnt; $invline_cnt_i++) {
                                         $do_invoiceline = new InvoiceLine();
                                         $invoiceline = $invoice->invoiceline[$invline_cnt_i];
                                         $do_invoiceline->idinvoice = $lastInsertedInvoiceId;
                                         $do_invoiceline->description = $invoiceline->description;
                                         $do_invoiceline->price = $invoiceline->price;
                                         $do_invoiceline->qty = $invoiceline->qty;
                                         $do_invoiceline->total = $invoiceline->total;
                                         $do_invoiceline->item = $invoiceline->item;
                                         $do_invoiceline->line_tax = $invoiceline->line_tax;
                                         $do_invoiceline->discounted_amount = $invoiceline->discounted_amount;
                                         $do_invoiceline->taxed_amount = $invoiceline->taxed_amount;
                                         $do_invoiceline->add();
                                         $do_invoiceline->free();
                                     }
                                 }
                                 //invoiceline import ends
                                 // recurrentinvoice
                                 $recinv_cnt = count($invoice->recurrentinvoice);
                                 if ($recinv_cnt) {
                                     for ($recinv_cnt_i = 0; $recinv_cnt_i < $recinv_cnt; $recinv_cnt_i++) {
                                         $do_recurrentinvoice = new RecurrentInvoice();
                                         $recurrentinvoice = $invoice->recurrentinvoice[$recinv_cnt_i];
                                         $do_recurrentinvoice->iduser = $_SESSION['do_User']->iduser;
                                         $do_recurrentinvoice->idinvoice = $lastInsertedInvoiceId;
                                         $do_recurrentinvoice->nextdate = $recurrentinvoice->nextdate;
                                         $do_recurrentinvoice->recurrence = $recurrentinvoice->recurrence;
                                         $do_recurrentinvoice->recurrencetype = $recurrentinvoice->recurrencetype;
                                         $do_recurrentinvoice->add();
                                         $do_recurrentinvoice->free();
                                     }
                                 }
                                 //recurrentinvoice import ends
                                 // Payment Log import
                                 $paymentlog_cnt = count($invoice->paymentlog);
                                 if ($paymentlog_cnt) {
                                     for ($paymentlog_cnt_i = 0; $paymentlog_cnt_i < $paymentlog_cnt; $paymentlog_cnt_i++) {
                                         $do_paymentlog = new PaymentLog();
                                         $paymentlog = $invoice->paymentlog[$paymentlog_cnt_i];
                                         $do_paymentlog->timestamp = $paymentlog->timestamp;
                                         $do_paymentlog->idinvoice = $lastInsertedInvoiceId;
                                         $do_paymentlog->amount = $paymentlog->amount;
                                         $do_paymentlog->payment_type = $paymentlog->payment_type;
                                         $do_paymentlog->ref_num = $paymentlog->ref_num;
                                         $do_paymentlog->date_added = $paymentlog->date_added;
                                         $do_paymentlog->add();
                                         $lastInsertedPaymentLogId = $do_paymentlog->getPrimaryKeyValue();
                                         //payment_invoice : Payment Invoice import
                                         $paymentinv_cnt = count($paymentlog->payment_invoice);
                                         if ($paymentinv_cnt) {
                                             for ($paymentinv_cnt_i = 0; $paymentinv_cnt_i < $paymentinv_cnt; $paymentinv_cnt_i++) {
                                                 $do_payment_invoice = new PaymentInvoice();
                                                 $paymentinvoice = $paymentlog->payment_invoice[$paymentinv_cnt_i];
                                                 $do_payment_invoice->idpayment = $lastInsertedPaymentLogId;
                                                 $do_payment_invoice->idinvoice = $lastInsertedInvoiceId;
                                                 $do_payment_invoice->amount = $paymentinvoice->amount;
                                                 $do_payment_invoice->add();
                                                 $do_payment_invoice->free();
                                             }
                                         }
                                         // payment_invoice import ends
                                         //paymentlog_extra_amount import
                                         $paymentlog_ext_amt_cnt = count($paymentlog->paymentlog_extra_amount);
                                         if ($paymentlog_ext_amt_cnt) {
                                             for ($paymentlog_ext_amt_cnt_i = 0; $paymentlog_ext_amt_cnt_i < $paymentlog_ext_amt_cnt; $paymentlog_ext_amt_cnt_i++) {
                                                 $paymentlog_extra_amount = $paymentlog->paymentlog_extra_amount[$paymentlog_ext_amt_cnt_i];
                                                 $q = new sqlQuery($GLOBALS['conx']);
                                                 $query = "INSERT INTO paymentlog_extra_amount (`idpaymentlog`,`extra_amt`,`iduser`)\n            VALUES (" . $lastInsertedPaymentLogId . "," . $paymentlog_extra_amount->extra_amt . "," . $_SESSION['do_User']->iduser . ")\n            ";
                                                 $q->query($query);
                                                 $q->free();
                                             }
                                         }
                                         // paymentlog_extra_amount import ends
                                         $do_paymentlog->free();
                                     }
                                 }
                                 //Payment Log import ends
                                 $msg_inv = ", Invoices";
                                 $do_invoice->free();
                             }
                         }
                         // Invoice import ends
                         /************************************************************************************************************************/
                         $do_contact->free();
                     }
                     $msg = "Your Contacts" . $msg_inv;
                 }
                 /**
                  *Company insert
                  */
                 $compani_id = array();
                 $lastInsertedCompani_id = array();
                 $companies_cnt = count($xml->companies);
                 if ($companies_cnt) {
                     for ($i = 0; $i < $companies_cnt; $i++) {
                         $do_company = new Company();
                         $company = $xml->companies[$i];
                         array_push($compani_id, "{$company->idcompany}");
                         // $do_company->idcompany=$company->idcompany;
                         $do_company->name = $company->name;
                         $do_company->iduser = $_SESSION['do_User']->iduser;
                         $do_company->add();
                         array_push($lastInsertedCompani_id, $do_company->getPrimaryKeyValue());
                         $do_company->free();
                     }
                 }
                 //tasks which are neither associated with Contact nor with project
                 $task_wop_cnt = count($xml->task_without_project);
                 if ($task_wop_cnt) {
                     for ($i = 0; $i < $task_wop_cnt; $i++) {
                         $do_task = new Task();
                         $task_wop = $xml->task_without_project[$i];
                         $do_task->task_description = $task_wop->task_description;
                         $do_task->due_date = $task_wop->due_date;
                         $do_task->category = $task_wop->category;
                         $do_task->iduser = $_SESSION['do_User']->iduser;
                         $do_task->due_date_dateformat = $task_wop->due_date_dateformat;
                         $do_task->status = $task_wop->status;
                         $do_task->date_completed = $task_wop->date_completed;
                         $do_task->idcontact = $task_wop->idcontact;
                         //it would be 0 since not associated with contact.
                         $do_task->from_note = $task_wop->from_note;
                         $do_task->is_sp_date_set = $task_wop->is_sp_date_set;
                         $do_task->task_category = $task_wop->task_category;
                         $do_task->add();
                         $do_task->free();
                     }
                     $msg .= ", Tasks";
                 }
                 //tasks which are associated with Project
                 $prj_cnt = count($xml->project);
                 if ($prj_cnt) {
                     for ($i = 0; $i < $prj_cnt; $i++) {
                         $do_project = new Project();
                         $project = $xml->project[$i];
                         $do_project->iduser = $_SESSION['do_User']->iduser;
                         $do_project->name = $project->name;
                         $do_project->end_date_dateformat = $project->end_date_dateformat;
                         $do_project->idcompany = $project->idcompany;
                         $do_project->status = $project->status;
                         $do_project->effort_estimated_hrs = $project->effort_estimated_hrs;
                         $do_project->is_public = $project->is_public;
                         $do_project->add();
                         $lastInsertedPrjId = $do_project->getPrimaryKeyValue();
                         $pt_cnt = count($project->project_task);
                         if ($pt_cnt) {
                             for ($pt_cnt_i = 0; $pt_cnt_i < $pt_cnt; $pt_cnt_i++) {
                                 $do_task = new Task();
                                 $project_task = $project->project_task[$pt_cnt_i];
                                 $do_task->task_description = $project_task->task_description;
                                 $do_task->due_date = $project_task->due_date;
                                 $do_task->category = $project_task->category;
                                 $do_task->iduser = $_SESSION['do_User']->iduser;
                                 $do_task->due_date_dateformat = $project_task->due_date_dateformat;
                                 $do_task->status = $project_task->status;
                                 $do_task->date_completed = $project_task->date_completed;
                                 $do_task->idcontact = $project_task->idcontact;
                                 $do_task->from_note = $project_task->from_note;
                                 $do_task->is_sp_date_set = $project_task->is_sp_date_set;
                                 $do_task->task_category = $project_task->task_category;
                                 $do_task->add();
                                 $lastInsertedTskId = $do_task->getPrimaryKeyValue();
                                 $q = new sqlQuery($GLOBALS['conx']);
                                 if ($project_task->progress == '') {
                                     $project_task_progress = 0;
                                 } else {
                                     $project_task_progress = $project_task->progress;
                                 }
                                 $sql = "INSERT INTO \n\t\t\tproject_task (idtask, idproject, progress,drop_box_code,priority,hrs_work_expected) \n\t\t\tVALUES ({$lastInsertedTskId},{$lastInsertedPrjId},{$project_task_progress},{$project_task->drop_box_code},{$project_task->priority},{$project_task->hrs_work_expected})";
                                 echo $sql;
                                 echo "<br>";
                                 $q->query($sql);
                                 $lastInsertedPrjTaskId = $q->getInsertId('project_task', 'idproject_task');
                                 $pd_cnt = count($project_task->project_discuss);
                                 if ($pd_cnt) {
                                     for ($pd_cnt_i = 0; $pd_cnt_i < $pd_cnt; $pd_cnt_i++) {
                                         $do_project_discuss = new ProjectDiscuss();
                                         $project_discuss = $project_task->project_discuss[$pd_cnt_i];
                                         $do_project_discuss->idproject_task = $lastInsertedPrjTaskId;
                                         $do_project_discuss->idtask = $lastInsertedTskId;
                                         $do_project_discuss->idproject = $lastInsertedPrjId;
                                         $do_project_discuss->discuss = $project_discuss->discuss;
                                         $do_project_discuss->date_added = $project_discuss->date_added;
                                         $do_project_discuss->document = $project_discuss->document;
                                         $do_project_discuss->iduser = $_SESSION['do_User']->iduser;
                                         $do_project_discuss->drop_box_sender = $project_discuss->drop_box_sender;
                                         $do_project_discuss->priority = $project_discuss->priority;
                                         $do_project_discuss->hours_work = $project_discuss->hours_work;
                                         $do_project_discuss->discuss_edit_access = $project_discuss->discuss_edit_access;
                                         $do_project_discuss->type = $project_discuss->type;
                                         $do_project_discuss->add();
                                         $do_project_discuss->free();
                                     }
                                 }
                                 // $do_project_task->free();
                                 $do_task->free();
                             }
                         }
                         $do_project->free();
                     }
                     $compani_id_cnt = count($compani_id);
                     if ($compani_id_cnt) {
                         $j = 0;
                         foreach ($compani_id as $cmp_id) {
                             $q = new sqlQuery($GLOBALS['conx']);
                             $sql = "UPDATE  contact SET idcompany ={$lastInsertedCompani_id[$j]}  WHERE  iduser={$_SESSION['do_User']->iduser} AND idcompany ={$cmp_id}";
                             $q->query($sql);
                             $sql1 = "UPDATE  invoice SET idcompany ={$lastInsertedCompani_id[$j]}  WHERE  iduser={$_SESSION['do_User']->iduser} AND idcompany ={$cmp_id}";
                             $q->query($sql1);
                             $sql2 = "UPDATE  project SET idcompany ={$lastInsertedCompani_id[$j]}  WHERE  iduser={$_SESSION['do_User']->iduser} AND idcompany ={$cmp_id}";
                             $q->query($sql2);
                             $q->free();
                             $j++;
                         }
                     }
                     $do_create_usrtbl = new ContactView();
                     $do_create_usrtbl->rebuildContactUserTable($_SESSION['do_User']->iduser);
                     $msg .= " and Projects have been imported successfully.";
                 }
             } else {
                 $msg = "Sorry! The data could not be imported.";
             }
         } else {
             $msg = "Sorry! Could not find the uploaded file.";
         }
     }
     $_SESSION['in_page_message'] = $msg;
 }