public static function repopulate_table()
 {
     $sql = "DELETE FROM `TestTemplate`";
     mysql_query($sql);
     $sql = "SELECT * FROM `TestSection`";
     $z = mysql_query($sql);
     while ($r = mysql_fetch_array($z)) {
         set_time_limit(0);
         if ($r['TestSectionType_id'] == DS_TestSectionType::LOAD_HTML_TEMPLATE) {
             $ts = TestSection::from_mysql_id($r['id']);
             $vals = $ts->get_values();
             $template = Template::from_mysql_id($vals[0]);
             if ($template != null) {
                 $html = Template::output_html($template->HTML, $vals, $template->get_outputs(), $template->get_inserts());
                 $test_template = new TestTemplate();
                 $test_template->Test_id = $r['Test_id'];
                 $test_template->TestSection_id = $r['id'];
                 $test_template->Template_id = $vals[0];
                 $test_template->HTML = $html;
                 $test_template->effect_show = $template->effect_show;
                 $test_template->effect_hide = $template->effect_hide;
                 $test_template->effect_show_options = $template->effect_show_options;
                 $test_template->effect_hide_options = $template->effect_hide_options;
                 $test_template->mysql_save();
             }
         }
     }
 }
Example #2
0
 public function mysql_save_from_post($post)
 {
     $lid = parent::mysql_save_from_post($post);
     $obj = static::from_mysql_id($lid);
     if ($obj != null) {
         $xml_hash = $obj->calculate_xml_hash();
         $obj->xml_hash = $xml_hash;
         $obj->mysql_save();
         $tt = TestTemplate::from_property(array("Template_id" => $lid));
         foreach ($tt as $elem) {
             $ts = TestSection::from_mysql_id($elem->TestSection_id);
             $vals = $ts->get_values();
             $html = Template::output_html($obj->HTML, $vals, $obj->get_outputs(), $obj->get_inserts());
             $elem->HTML = $html;
             $elem->mysql_save();
         }
     }
     return $lid;
 }
Example #3
0
 public function mysql_save_from_post($post)
 {
     $lid = parent::mysql_save_from_post($post);
     $sections = array();
     if (isset($post['sections'])) {
         $sections = json_decode($post["sections"], true);
     }
     if ($this->id != 0) {
         $this->delete_sections();
         $this->delete_templates();
         $this->delete_object_links(TestVariable::get_mysql_table());
         $i = 0;
     } else {
         $found = false;
         foreach ($sections as $section) {
             if ($section['counter'] == 1) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $start_section = new TestSection();
             $start_section->TestSectionType_id = DS_TestSectionType::START;
             $start_section->Test_id = $lid;
             $start_section->counter = 1;
             $start_section->mysql_save();
         }
         $found = false;
         foreach ($sections as $section) {
             if ($section['counter'] == 2) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $end_section = new TestSection();
             $end_section->TestSectionType_id = DS_TestSectionType::END;
             $end_section->Test_id = $lid;
             $end_section->counter = 2;
             $end_section->mysql_save();
         }
     }
     $i = 0;
     if (array_key_exists("parameters", $post)) {
         foreach ($post["parameters"] as $param) {
             $p = json_decode($param);
             $var = new TestVariable();
             $var->description = $p->description;
             $var->name = $p->name;
             $var->index = $i;
             $var->type = 0;
             $var->Test_id = $lid;
             $var->mysql_save();
             $i++;
         }
     }
     if (array_key_exists("returns", $post)) {
         foreach ($post["returns"] as $ret) {
             $r = json_decode($ret);
             $var = new TestVariable();
             $var->description = $r->description;
             $var->name = $r->name;
             $var->index = $i;
             $var->type = 1;
             $var->Test_id = $lid;
             $var->mysql_save();
             $i++;
         }
     }
     foreach ($sections as $section) {
         $s = new TestSection();
         $s->counter = $section['counter'];
         $s->TestSectionType_id = $section['type'];
         $s->end = $section['end'];
         $s->Test_id = $lid;
         $s->parent_counter = $section['parent'];
         $slid = $s->mysql_save();
         $vals = $section['value'];
         foreach ($vals as $k => $v) {
             $index = substr($k, 1);
             $value = $v;
             $sv = new TestSectionValue();
             $sv->TestSection_id = $slid;
             $sv->index = $index;
             $sv->value = $value;
             $sv->mysql_save();
         }
         if ($s->TestSectionType_id == DS_TestSectionType::LOAD_HTML_TEMPLATE) {
             $ts = TestSection::from_mysql_id($slid);
             $vals = $ts->get_values();
             $template = Template::from_mysql_id($vals[0]);
             if ($template != null) {
                 $html = Template::output_html($template->HTML, $vals, $template->get_outputs(), $template->get_inserts());
                 $test_template = new TestTemplate();
                 $test_template->Test_id = $lid;
                 $test_template->TestSection_id = $slid;
                 $test_template->Template_id = $vals[0];
                 $test_template->HTML = $html;
                 $test_template->mysql_save();
             }
         }
     }
     $sql = sprintf("DELETE FROM `%s` WHERE `Test_id`=%d", TestProtectedVariable::get_mysql_table(), $lid);
     mysql_query($sql);
     if (array_key_exists("protected", $post)) {
         foreach ($post['protected'] as $var) {
             $var = json_decode($var);
             $s = new TestProtectedVariable();
             $s->name = $var->name;
             $s->Test_id = $lid;
             $slid = $s->mysql_save();
         }
     }
     $obj = static::from_mysql_id($lid);
     if ($obj != null) {
         $xml_hash = $obj->calculate_xml_hash();
         $obj->xml_hash = $xml_hash;
         $obj->mysql_save();
     }
     return $lid;
 }