Umfragen
stresstest2.php
Go to the documentation of this file.
1 <?php
2 /*
3  * untitled.php
4  *
5  * Copyright 2013 Johannes ter Haak <jojo@jojo-42>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24 
25 
26 
27 require_once("config.php");
28 require_once("inc/tools.php");
29 
30 require_once("inc/db.class.php");
31 require_once("inc/poll.class.php");
32 require_once("inc/widget.class.php");
33 require_once("inc/auth.class.php");
34 
35 
36 function RandString2($length = 10) {
37  $characters = '0123456789abcdefghijklmnopqrstuvwxyz ';
38  $string = "";
39  for ($p = 0; $p < $length; $p++) {
40  $string .= $characters[mt_rand(0, strlen($characters)-1)];
41  }
42  return $string;
43 }
44 
45 
46 $db= new db( DB_USER, DB_PASS, DB_DATABASE, DB_HOST );
48 
49 if( !(isset($_SESSION)) ){
50  session_start();
51 }
52 
53 // groups and users
54 $groups = $au->get_all_groups();
55 $all_groups = array();
56 foreach($groups as $gr){
57  $all_groups[] = $gr[1];
58 }
59 $users = $au->get_all_users_from_grouplist($all_groups);
60 $groups_users = array();
61 foreach( $users as $user ){
62  if(!isset($groups_users[$user["groupID"]]) ){
63  $groups_users[$user["groupID"]] = array( $user );
64  }else{
65  $groups_users[$user["groupID"]][] = $user ;
66  }
67 }
68 
69 // get all polls
70 $polls_array = $db->get_all_polls_array();
71 $polls = array();
72 foreach( $polls_array as $p ){
73  $poll = new poll();
74  $poll->load_from_id($db,$p["ID"]);
75  $polls[] = $poll;
76 }
77 
78 
79 // go through all polls
80 $count = 1;
81 foreach( $polls as $poll ){
82  if( $poll->anonymous === false ){
83  if( in_array("*",$poll->groups) ){
84  $groups_all = $all_groups;
85  }else{
86  $groups_all = $poll->groups;
87  }
88  foreach( $groups_all as $g ){
89  foreach( $groups_users[$g] as $user ){
90  $_SESSION["user"] = $user["userName"];
91  $_SESSION["fullName"] = $user["fullName"];
92  $_SESSION["group"] = $user["groupID"];
93  $_SESSION["groupName"] = $user["groupID"];
94  foreach( $poll->widget_list as $widget ){
95  if( $widget instanceof radioButtonList ){
96  $widget->value = $widget->option_list[ mt_rand(0,sizeof($widget->option_list)-1) ]->value;
97  }else if ($widget instanceof text ){
98  $widget->value = RandString2(20);
99  }else if ($widget instanceof matrix ){
100  foreach( $widget->question_list as $question ){
101  $question->value = $widget->option_list[ mt_rand(0,sizeof($widget->option_list)-1) ]->value;
102  }
103  }
104  } // end foreach widget
105  $db->insert_poll_result($poll);
106  } // end foreach user
107  } // end foreach group
108  }else{
109  for( $cc=0 ; $cc < 400 ; ++$cc ){
110  foreach( $poll->widget_list as $widget ){
111  if( $widget instanceof radioButtonList ){
112  $widget->value = $widget->option_list[ mt_rand(0,sizeof($widget->option_list)-1) ]->value;
113  }else if ($widget instanceof text ){
114  $widget->value = RandString2(20);
115  }else if ($widget instanceof matrix ){
116  foreach( $widget->question_list as $question ){
117  $question->value = $widget->option_list[ mt_rand(0,sizeof($widget->option_list)-1) ]->value;
118  }
119  }
120  } // end foreach widget
121  }
122  }
123  $tot = sizeof($polls);
124  error_log("results injected for poll $count of $tot (pollID {$poll->ID})");
125  ++$count;
126 }
127 
128 
129 ?>
130