Changeset 540441
- Timestamp:
- 05/06/2012 09:47:42 AM (14 years ago)
- Location:
- surveypress
- Files:
-
- 2 added
- 6 edited
-
tags/1.0.9/survey-press.php (modified) (6 diffs)
-
tags/1.0.9/view/config-menu.php (modified) (2 diffs)
-
tags/1.0.9/view/option-menu.php (modified) (5 diffs)
-
tags/1.0.9/view/tokens-menu.php (added)
-
trunk/survey-press.php (modified) (6 diffs)
-
trunk/view/config-menu.php (modified) (2 diffs)
-
trunk/view/option-menu.php (modified) (5 diffs)
-
trunk/view/tokens-menu.php (added)
Legend:
- Unmodified
- Added
- Removed
-
surveypress/tags/1.0.9/survey-press.php
r506161 r540441 21 21 Description: <strong>LimeSurvey + WordPress = A perfect combination of blog fully capable of managing surveys</strong>. Using this plugin, you can integrate LimeSurvey with WordPress to make registered users take surveys. Allow them to make their own survey(s) and so on. 22 22 Version: 1.0.9 23 Author URI: http:// sachdevashubham.blogspot.com/23 Author URI: http://docs.limesurvey.org/UserPage+magiclko 24 24 License: GPLv2 25 25 */ … … 59 59 60 60 /** 61 * Global variables assosciated with tokens screen 62 */ 63 64 // variables for the option menu content. 65 $option_token_basis = 'token_basis'; 66 $option_token_uses = 'token_uses'; 67 $token_option_sid_list = 'token_sid_list'; 68 // respective values from database. 69 // Read in existing option value from database 70 $token_value_sid_list = get_option( $token_option_sid_list ); 71 72 $value_token_uses = get_option( $option_token_uses ); 73 if ( $value_token_uses != '' ) 74 { 75 $value_token_uses = (int) $value_token_uses; 76 } 77 78 if ( get_option( $option_token_basis ) == '' ) 79 { 80 $value_token_basis = 1; 81 } 82 else 83 { 84 $value_token_basis = (int) get_option( $option_token_basis ); 85 } 86 87 88 $map_role_subscriber_token = (int) get_option( 'map_role_subscriber_token' ); 89 $map_role_administrator_token = (int) get_option( 'map_role_administrator_token' ); 90 $map_role_editor_token = (int) get_option( 'map_role_editor_token' ); 91 $map_role_author_token = (int) get_option( 'map_role_author_token' ); 92 $map_role_contributor_token = (int) get_option( 'map_role_contributor_token' ); 93 94 /** 61 95 * Global variables assosciated with option screen 62 96 */ … … 68 102 $same_option_password = 'same_password'; 69 103 $list_option_public_surveys = 'list_public_survey_only'; 70 $token_option_sid_list = 'token_sid_list'; 104 71 105 // respective values from database. 72 106 // Read in existing option value from database 73 $token_value_sid_list = get_option( $token_option_sid_list );74 107 75 108 if ( get_option( $apply_option_default_permissions ) == '' ) … … 118 151 } 119 152 120 $map_role_subscriber_token = (int) get_option( 'map_role_subscriber_token' );121 $map_role_administrator_token = (int) get_option( 'map_role_administrator_token' );122 $map_role_editor_token = (int) get_option( 'map_role_editor_token' );123 $map_role_author_token = (int) get_option( 'map_role_author_token' );124 $map_role_contributor_token = (int) get_option( 'map_role_contributor_token' );125 153 126 154 /** … … 222 250 add_action( 'load-' . $hook_suffix_top_menu , array('Bridge_WP_LS','an_top_menu_loaded') ); 223 251 224 // Add a s econd submenu to the custom top-level menu:252 // Add a submenu to the custom top-level menu: 225 253 add_submenu_page('an-survey-config', __('Map the roles and user permissions','menu-test'), __('Mapping','menu-test'), 'manage_options', 'an-bridge-map',array('Bridge_WP_LS', 'an_add_menu_mapping')); 226 254 255 // Add a submenu to the custom top-level menu: 256 add_submenu_page('an-survey-config', __('Tokens','menu-test'), __('Tokens','menu-test'), 'manage_options', 'an-bridge-tokens',array('Bridge_WP_LS', 'an_add_menu_tokens')); 257 227 258 // Add a submenu to the custom top-level menu: 228 259 add_submenu_page('an-survey-config', __('Customize','menu-test'), __('Customize','menu-test'), 'manage_options', 'an-bridge-opt', array('Bridge_WP_LS', 'an_add_menu_options')); … … 256 287 } 257 288 include 'view/mapping-menu.php'; 289 } 290 291 // an_add_top_menu() displays the page content for the custom Test Toplevel menu 292 /** 293 * Bridge_WP_LS::an_add_config_menu() 294 * adds configuration page. It displays configuration options pertaining to LimeSurvey. 295 * @return 296 */ 297 function an_add_menu_tokens() 298 { 299 if (!current_user_can('manage_options')) 300 { 301 wp_die( __('You do not have sufficient permissions to access this page.') ); 302 } 303 include 'view/tokens-menu.php'; 258 304 } 259 305 -
surveypress/tags/1.0.9/view/config-menu.php
r506161 r540441 12 12 global $list_value_public_surveys,$show_value_survey_notification,$db_connection_error_name,$db_connection_error; 13 13 14 global $value_token_basis,$value_token_uses,$token_value_sid_list; 15 global $map_role_subscriber_token,$map_role_administrator_token,$map_role_editor_token,$map_role_author_token,$map_role_contributor_token; 16 17 18 function randomChars($length,$pattern="23456789abcdefghijkmnpqrstuvwxyz") 19 { 20 $patternlength = strlen($pattern)-1; 21 for($i=0;$i<$length;$i++) 22 { 23 if(isset($key)) 24 $key .= $pattern{rand(0,$patternlength)}; 25 else 26 $key = $pattern{rand(0,$patternlength)}; 27 } 28 return $key; 29 } 14 30 15 31 //if user is administrator … … 197 213 global $current_user; 198 214 get_currentuserinfo(); 215 216 //deal with tokens first! 217 if ( !$value_token_basis ) 218 { 219 //check if $token_option_sid_list is not empty 220 if ( $token_value_sid_list != '' || $token_value_sid_list != null ) 221 { 222 $sid_tokens = explode( ',', $token_value_sid_list ); 223 224 foreach ($sid_tokens as $sid) 225 { 226 $sid = (int) $sid; 227 $lang = $lsdb->get_var( $lsdb->prepare( "SELECT language FROM ".$db_value_prefix."surveys WHERE sid=".$sid.";" ) ); 228 229 //find the role of current user 230 $user_roles = $current_user->roles; 231 $user_role = array_shift($user_roles); 232 $proceed = FALSE; 233 234 switch ($user_role) { 235 236 case "subscriber": 237 if ( $map_role_subscriber_token ) 238 $proceed = TRUE; 239 break; 240 241 case "editor": 242 if ( $map_role_editor_token ) 243 $proceed = TRUE; 244 break; 245 246 case "administrator": 247 if ( $map_role_administrator_token ) 248 $proceed = TRUE; 249 break; 250 251 case "author": 252 if ( $map_role_author_token ) 253 $proceed = TRUE; 254 break; 255 256 case "contributor": 257 if ( $map_role_contributor_token ) 258 $proceed = TRUE; 259 break; 260 261 } 262 263 if ( $proceed ) 264 { 265 //check whether a token for this user is already inserted or not? 266 $query = "SELECT token 267 FROM ".$db_value_prefix."tokens_".$sid." 268 WHERE firstname='".$current_user->user_login."' 269 AND lastname='".$current_user->display_name."' 270 AND email='".$current_user->user_email."'"; 271 272 $token = $lsdb->get_var( $lsdb->prepare( $query ) ); 273 274 if ( is_null( $token ) ) 275 { 276 //token doesn't exist, insert one! 277 $isvalidtoken = false; 278 while ($isvalidtoken == false) 279 { 280 $newtoken = randomChars(15); 281 //ensure same token isn't already in database! 282 283 $query = "SELECT firstname 284 FROM ".$db_value_prefix."tokens_".$sid." 285 WHERE token='".$newtoken."' 286 AND lastname='".$current_user->display_name."' 287 AND email='".$current_user->user_email."'"; 288 289 $temp = $lsdb->get_var( $lsdb->prepare( $query ) ); 290 291 if ( is_null( $temp ) ) 292 { 293 $isvalidtoken = true; 294 } 295 } 296 297 $sanitizedtoken = $newtoken; 298 299 $insert_token = $lsdb->insert( 300 $db_value_prefix.'tokens_'.$sid, 301 array( 302 'firstname' => $current_user->user_login, 303 'lastname' => $current_user->display_name, 304 'email' => $current_user->user_email, 305 'emailstatus' => "OK", 306 'token' => $sanitizedtoken, 307 'language' => $lang, 308 'sent' => 'N', 309 'remindersent' => 'N', 310 'completed' => 'N', 311 'usesleft' => $value_token_uses 312 ), 313 array( 314 '%s', 315 '%s', 316 '%s', 317 '%s', 318 '%s', 319 '%s', 320 '%s', 321 '%s', 322 '%s', 323 '%d' 324 ) 325 ); 326 } 327 328 } 329 330 331 332 } 333 } 334 335 336 337 } 338 339 199 340 //$lsdb = new wpdb( $db_value_user, $db_value_pwd, $db_value_name, $db_value_host ); 200 341 $query = "SELECT a.sid, b.surveyls_title, a.listpublic -
surveypress/tags/1.0.9/view/option-menu.php
r505547 r540441 9 9 global $apply_option_default_permissions,$show_option_survey_notification,$show_option_import_users,$same_option_password,$list_option_public_surveys; 10 10 global $apply_value_default_permissions,$show_value_survey_notification,$show_value_import_users,$same_value_password,$list_value_public_surveys; 11 global $token_option_sid_list,$token_value_sid_list,$db_value_prefix; 12 global $map_role_subscriber_token,$map_role_administrator_token,$map_role_editor_token,$map_role_author_token,$map_role_contributor_token; 11 global $db_value_prefix; 13 12 global $lsdb; 14 15 16 function randomChars($length,$pattern="23456789abcdefghijkmnpqrstuvwxyz")17 {18 $patternlength = strlen($pattern)-1;19 for($i=0;$i<$length;$i++)20 {21 if(isset($key))22 $key .= $pattern{rand(0,$patternlength)};23 else24 $key = $pattern{rand(0,$patternlength)};25 }26 return $key;27 }28 13 29 14 //output the heading. … … 54 39 $same_value_password = (int) $_POST[ $same_option_password ]; 55 40 $list_value_public_surveys = (int) $_POST[ $list_option_public_surveys ]; 56 $token_value_sid_list = $_POST[ $token_option_sid_list ];41 57 42 58 $map_role_subscriber_token = (int) ( isset($_POST['map_role_subscriber_token']) ) ? ( $_POST['map_role_subscriber_token'] ) : ( 0 );59 $map_role_administrator_token = (int) ( isset($_POST['map_role_administrator_token']) ) ? ( $_POST['map_role_administrator_token'] ) : ( 0 );60 $map_role_editor_token = (int) ( isset($_POST['map_role_editor_token']) ) ? ( $_POST['map_role_editor_token'] ) : ( 0 );61 $map_role_author_token = (int) ( isset($_POST['map_role_author_token']) ) ? ( $_POST['map_role_author_token'] ) : ( 0 );62 $map_role_contributor_token = (int) ( isset($_POST['map_role_contributor_token']) ) ? ( $_POST['map_role_contributor_token'] ) : ( 0 );63 64 43 // Save the posted values in the database 65 44 update_option( $apply_option_default_permissions, $apply_value_default_permissions ); … … 68 47 update_option( $same_option_password, $same_value_password ); 69 48 update_option( $list_option_public_surveys, $list_value_public_surveys ); 70 update_option( $token_option_sid_list, $token_value_sid_list );71 49 72 update_option( 'map_role_subscriber_token', $map_role_subscriber_token );73 update_option( 'map_role_administrator_token', $map_role_administrator_token );74 update_option( 'map_role_editor_token', $map_role_editor_token );75 update_option( 'map_role_author_token', $map_role_author_token );76 update_option( 'map_role_contributor_token', $map_role_contributor_token );77 78 79 //check if $token_option_sid_list is not empty80 if ( $token_value_sid_list != '' || $token_value_sid_list != null )81 {82 $sid_token = explode( ',', $token_value_sid_list );83 84 foreach ($sid_token as $sid)85 {86 $sid = (int) $sid;87 $lang = $lsdb->get_var( $lsdb->prepare( "SELECT language FROM ".$db_value_prefix."surveys WHERE sid=".$sid.";" ) );88 //add tokens for users with specified roles.89 //subscriber90 if((int)$map_role_subscriber_token)91 {92 $users = get_users('role=subscriber');93 foreach ($users as $user) {94 95 $isvalidtoken = false;96 while ($isvalidtoken == false)97 {98 $newtoken = randomChars(15);99 if (!isset($existingtokens[$newtoken]))100 {101 $isvalidtoken = true;102 $existingtokens[$newtoken] = null;103 }104 }105 $sanitizedtoken = $newtoken;106 107 $subscriber = $lsdb->insert(108 $db_value_prefix.'tokens_'.$sid,109 array(110 'firstname' => $user->user_login,111 'lastname' => $user->display_name,112 'email' => $user->user_email,113 'emailstatus' => "OK",114 'token' => $sanitizedtoken,115 'language' => $lang,116 'sent' => 'N',117 'remindersent' => 'N',118 'completed' => 'N',119 'usesleft' => 1120 ),121 array(122 '%s',123 '%s',124 '%s',125 '%s',126 '%s',127 '%s',128 '%s',129 '%s',130 '%s',131 '%d'132 )133 );134 }135 }136 137 //administrator role138 if((int)$map_role_administrator_token)139 {140 $users = get_users('role=administrator');141 foreach ($users as $user) {142 143 $isvalidtoken = false;144 while ($isvalidtoken == false)145 {146 $newtoken = randomChars(15);147 if (!isset($existingtokens[$newtoken]))148 {149 $isvalidtoken = true;150 $existingtokens[$newtoken] = null;151 }152 }153 $sanitizedtoken = $newtoken;154 155 $administrator = $lsdb->insert(156 $db_value_prefix.'tokens_'.$sid,157 array(158 'firstname' => $user->user_login,159 'lastname' => $user->display_name,160 'email' => $user->user_email,161 'emailstatus' => "OK",162 'token' => $sanitizedtoken,163 'language' => $lang,164 'sent' => 'N',165 'remindersent' => 'N',166 'completed' => 'N',167 'usesleft' => 1168 ),169 array(170 '%s',171 '%s',172 '%s',173 '%s',174 '%s',175 '%s',176 '%s',177 '%s',178 '%s',179 '%d'180 )181 );182 }183 }184 185 //editor role186 if((int)$map_role_editor_token)187 {188 $users = get_users('role=editor');189 foreach ($users as $user) {190 191 $isvalidtoken = false;192 while ($isvalidtoken == false)193 {194 $newtoken = randomChars(15);195 if (!isset($existingtokens[$newtoken]))196 {197 $isvalidtoken = true;198 $existingtokens[$newtoken] = null;199 }200 }201 $sanitizedtoken = $newtoken;202 203 $editor = $lsdb->insert(204 $db_value_prefix.'tokens_'.$sid,205 array(206 'firstname' => $user->user_login,207 'lastname' => $user->display_name,208 'email' => $user->user_email,209 'emailstatus' => "OK",210 'token' => $sanitizedtoken,211 'language' => $lang,212 'sent' => 'N',213 'remindersent' => 'N',214 'completed' => 'N',215 'usesleft' => 1216 ),217 array(218 '%s',219 '%s',220 '%s',221 '%s',222 '%s',223 '%s',224 '%s',225 '%s',226 '%s',227 '%d'228 )229 );230 }231 }232 233 //author role234 if((int)$map_role_author_token)235 {236 $users = get_users('role=author');237 foreach ($users as $user) {238 239 $isvalidtoken = false;240 while ($isvalidtoken == false)241 {242 $newtoken = randomChars(15);243 if (!isset($existingtokens[$newtoken]))244 {245 $isvalidtoken = true;246 $existingtokens[$newtoken] = null;247 }248 }249 $sanitizedtoken = $newtoken;250 251 $author = $lsdb->insert(252 $db_value_prefix.'tokens_'.$sid,253 array(254 'firstname' => $user->user_login,255 'lastname' => $user->display_name,256 'email' => $user->user_email,257 'emailstatus' => "OK",258 'token' => $sanitizedtoken,259 'language' => $lang,260 'sent' => 'N',261 'remindersent' => 'N',262 'completed' => 'N',263 'usesleft' => 1264 ),265 array(266 '%s',267 '%s',268 '%s',269 '%s',270 '%s',271 '%s',272 '%s',273 '%s',274 '%s',275 '%d'276 )277 );278 }279 }280 281 //contributor role282 if((int)$map_role_contributor_token)283 {284 $users = get_users('role=contributor');285 foreach ($users as $user) {286 287 $isvalidtoken = false;288 while ($isvalidtoken == false)289 {290 $newtoken = randomChars(15);291 if (!isset($existingtokens[$newtoken]))292 {293 $isvalidtoken = true;294 $existingtokens[$newtoken] = null;295 }296 }297 $sanitizedtoken = $newtoken;298 299 $contributor = $lsdb->insert(300 $db_value_prefix.'tokens_'.$sid,301 array(302 'firstname' => $user->user_login,303 'lastname' => $user->display_name,304 'email' => $user->user_email,305 'emailstatus' => "OK",306 'token' => $sanitizedtoken,307 'language' => $lang,308 'sent' => 'N',309 'remindersent' => 'N',310 'completed' => 'N',311 'usesleft' => 1312 ),313 array(314 '%s',315 '%s',316 '%s',317 '%s',318 '%s',319 '%s',320 '%s',321 '%s',322 '%s',323 '%d'324 )325 );326 }327 }328 }329 330 331 }332 333 $token_msg = '';334 if ( $token_value_sid_list != '' || $token_value_sid_list != null )335 {336 //construct new message!337 $token_msg = " Tokens added for users with roles :";338 if( (int)$map_role_subscriber_token )339 {340 $token_msg .= " Subscriber";341 }342 if( (int)$map_role_administrator_token )343 {344 $token_msg .= " Administrator";345 }346 if( (int)$map_role_editor_token )347 {348 $token_msg .= " Editor";349 }350 if( (int)$map_role_author_token )351 {352 $token_msg .= " Author";353 }354 if( (int)$map_role_contributor_token )355 {356 $token_msg .= " Contributor";357 }358 $token_msg .=" in survey(s) with surveyid(s) :";359 360 $sid_token = explode( ',', $token_value_sid_list );361 foreach ( $sid_token as $sid )362 {363 $token_msg .= " ".$sid;364 }365 366 $token_msg .=".";367 }368 369 //unset values;370 $token_value_sid_list = '';371 $map_role_subscriber_token = 0;372 $map_role_administrator_token = 0;373 $map_role_editor_token = 0;374 $map_role_author_token = 0;375 $map_role_contributor_token = 0;376 377 update_option( $token_option_sid_list, $token_value_sid_list );378 379 update_option( 'map_role_subscriber_token', $map_role_subscriber_token );380 update_option( 'map_role_administrator_token', $map_role_administrator_token );381 update_option( 'map_role_editor_token', $map_role_editor_token );382 update_option( 'map_role_author_token', $map_role_author_token );383 update_option( 'map_role_contributor_token', $map_role_contributor_token );384 50 // Put an settings updated message on the screen 385 51 … … 388 54 <div class='updated'> 389 55 <p><strong><?php _e('Settings saved.', 'menu-test' ); 390 if ( $token_msg != '' ) echo $token_msg; ?></strong></p> 56 ?> 57 </strong></p> 391 58 </div> 392 59 … … 475 142 </tr> 476 143 477 <tr valign="top"> 478 <th scope="row"> 479 <?php _e("Add token for users with following roles:", 'menu-test' ); ?> 480 </th> 481 <td> 482 <p> 483 <label> 484 <input type="checkbox" name="map_role_subscriber_token" value="1" <?php if((int)$map_role_subscriber_token) { ?> checked="checked" <?php } ?> /> 485 <?php _e("Subscriber"); ?> 486 </label> 487 488 <label> 489 <input type="checkbox" name="map_role_administrator_token" value="1" <?php if((int)$map_role_administrator_token) { ?> checked="checked" <?php } ?> /> 490 <?php _e("Administrator"); ?> 491 </label> 492 493 <label> 494 <input type="checkbox" name="map_role_editor_token" value="1" <?php if((int)$map_role_editor_token) { ?> checked="checked" <?php } ?> /> 495 <?php _e("Editor"); ?> 496 </label> 497 498 <label> 499 <input type="checkbox" name="map_role_author_token" value="1" <?php if((int)$map_role_author_token) { ?> checked="checked" <?php } ?> /> 500 <?php _e("Author"); ?> 501 </label> 502 503 <label> 504 <input type="checkbox" name="map_role_contributor_token" value="1" <?php if((int)$map_role_contributor_token) { ?> checked="checked" <?php } ?> /> 505 <?php _e("Contributor"); ?> 506 </label> 507 <br /> 508 <b><?php _e("In surveys with surveyid:"); ?></b><br /> 509 <input type="text" name="<?php echo $token_option_sid_list; ?>" id="<?php echo $token_option_sid_list; ?>" value="<?php echo $token_value_sid_list; ?>" size="20" class="regular-text" /> 510 <span class="description">( Comma(,) separated list of surveyid(s) for which tokens must be added to there respective tables. )</span> 511 <br /><span class="description">( Users with checked role(s) will have a token each in specified surveys above. Token added can be used only once! )</span> 512 513 </p> 514 </td> 515 </tr> 516 144 517 145 <tr valign="top"> 518 146 <th scope="row"> -
surveypress/trunk/survey-press.php
r506161 r540441 21 21 Description: <strong>LimeSurvey + WordPress = A perfect combination of blog fully capable of managing surveys</strong>. Using this plugin, you can integrate LimeSurvey with WordPress to make registered users take surveys. Allow them to make their own survey(s) and so on. 22 22 Version: 1.0.9 23 Author URI: http:// sachdevashubham.blogspot.com/23 Author URI: http://docs.limesurvey.org/UserPage+magiclko 24 24 License: GPLv2 25 25 */ … … 59 59 60 60 /** 61 * Global variables assosciated with tokens screen 62 */ 63 64 // variables for the option menu content. 65 $option_token_basis = 'token_basis'; 66 $option_token_uses = 'token_uses'; 67 $token_option_sid_list = 'token_sid_list'; 68 // respective values from database. 69 // Read in existing option value from database 70 $token_value_sid_list = get_option( $token_option_sid_list ); 71 72 $value_token_uses = get_option( $option_token_uses ); 73 if ( $value_token_uses != '' ) 74 { 75 $value_token_uses = (int) $value_token_uses; 76 } 77 78 if ( get_option( $option_token_basis ) == '' ) 79 { 80 $value_token_basis = 1; 81 } 82 else 83 { 84 $value_token_basis = (int) get_option( $option_token_basis ); 85 } 86 87 88 $map_role_subscriber_token = (int) get_option( 'map_role_subscriber_token' ); 89 $map_role_administrator_token = (int) get_option( 'map_role_administrator_token' ); 90 $map_role_editor_token = (int) get_option( 'map_role_editor_token' ); 91 $map_role_author_token = (int) get_option( 'map_role_author_token' ); 92 $map_role_contributor_token = (int) get_option( 'map_role_contributor_token' ); 93 94 /** 61 95 * Global variables assosciated with option screen 62 96 */ … … 68 102 $same_option_password = 'same_password'; 69 103 $list_option_public_surveys = 'list_public_survey_only'; 70 $token_option_sid_list = 'token_sid_list'; 104 71 105 // respective values from database. 72 106 // Read in existing option value from database 73 $token_value_sid_list = get_option( $token_option_sid_list );74 107 75 108 if ( get_option( $apply_option_default_permissions ) == '' ) … … 118 151 } 119 152 120 $map_role_subscriber_token = (int) get_option( 'map_role_subscriber_token' );121 $map_role_administrator_token = (int) get_option( 'map_role_administrator_token' );122 $map_role_editor_token = (int) get_option( 'map_role_editor_token' );123 $map_role_author_token = (int) get_option( 'map_role_author_token' );124 $map_role_contributor_token = (int) get_option( 'map_role_contributor_token' );125 153 126 154 /** … … 222 250 add_action( 'load-' . $hook_suffix_top_menu , array('Bridge_WP_LS','an_top_menu_loaded') ); 223 251 224 // Add a s econd submenu to the custom top-level menu:252 // Add a submenu to the custom top-level menu: 225 253 add_submenu_page('an-survey-config', __('Map the roles and user permissions','menu-test'), __('Mapping','menu-test'), 'manage_options', 'an-bridge-map',array('Bridge_WP_LS', 'an_add_menu_mapping')); 226 254 255 // Add a submenu to the custom top-level menu: 256 add_submenu_page('an-survey-config', __('Tokens','menu-test'), __('Tokens','menu-test'), 'manage_options', 'an-bridge-tokens',array('Bridge_WP_LS', 'an_add_menu_tokens')); 257 227 258 // Add a submenu to the custom top-level menu: 228 259 add_submenu_page('an-survey-config', __('Customize','menu-test'), __('Customize','menu-test'), 'manage_options', 'an-bridge-opt', array('Bridge_WP_LS', 'an_add_menu_options')); … … 256 287 } 257 288 include 'view/mapping-menu.php'; 289 } 290 291 // an_add_top_menu() displays the page content for the custom Test Toplevel menu 292 /** 293 * Bridge_WP_LS::an_add_config_menu() 294 * adds configuration page. It displays configuration options pertaining to LimeSurvey. 295 * @return 296 */ 297 function an_add_menu_tokens() 298 { 299 if (!current_user_can('manage_options')) 300 { 301 wp_die( __('You do not have sufficient permissions to access this page.') ); 302 } 303 include 'view/tokens-menu.php'; 258 304 } 259 305 -
surveypress/trunk/view/config-menu.php
r506161 r540441 12 12 global $list_value_public_surveys,$show_value_survey_notification,$db_connection_error_name,$db_connection_error; 13 13 14 global $value_token_basis,$value_token_uses,$token_value_sid_list; 15 global $map_role_subscriber_token,$map_role_administrator_token,$map_role_editor_token,$map_role_author_token,$map_role_contributor_token; 16 17 18 function randomChars($length,$pattern="23456789abcdefghijkmnpqrstuvwxyz") 19 { 20 $patternlength = strlen($pattern)-1; 21 for($i=0;$i<$length;$i++) 22 { 23 if(isset($key)) 24 $key .= $pattern{rand(0,$patternlength)}; 25 else 26 $key = $pattern{rand(0,$patternlength)}; 27 } 28 return $key; 29 } 14 30 15 31 //if user is administrator … … 197 213 global $current_user; 198 214 get_currentuserinfo(); 215 216 //deal with tokens first! 217 if ( !$value_token_basis ) 218 { 219 //check if $token_option_sid_list is not empty 220 if ( $token_value_sid_list != '' || $token_value_sid_list != null ) 221 { 222 $sid_tokens = explode( ',', $token_value_sid_list ); 223 224 foreach ($sid_tokens as $sid) 225 { 226 $sid = (int) $sid; 227 $lang = $lsdb->get_var( $lsdb->prepare( "SELECT language FROM ".$db_value_prefix."surveys WHERE sid=".$sid.";" ) ); 228 229 //find the role of current user 230 $user_roles = $current_user->roles; 231 $user_role = array_shift($user_roles); 232 $proceed = FALSE; 233 234 switch ($user_role) { 235 236 case "subscriber": 237 if ( $map_role_subscriber_token ) 238 $proceed = TRUE; 239 break; 240 241 case "editor": 242 if ( $map_role_editor_token ) 243 $proceed = TRUE; 244 break; 245 246 case "administrator": 247 if ( $map_role_administrator_token ) 248 $proceed = TRUE; 249 break; 250 251 case "author": 252 if ( $map_role_author_token ) 253 $proceed = TRUE; 254 break; 255 256 case "contributor": 257 if ( $map_role_contributor_token ) 258 $proceed = TRUE; 259 break; 260 261 } 262 263 if ( $proceed ) 264 { 265 //check whether a token for this user is already inserted or not? 266 $query = "SELECT token 267 FROM ".$db_value_prefix."tokens_".$sid." 268 WHERE firstname='".$current_user->user_login."' 269 AND lastname='".$current_user->display_name."' 270 AND email='".$current_user->user_email."'"; 271 272 $token = $lsdb->get_var( $lsdb->prepare( $query ) ); 273 274 if ( is_null( $token ) ) 275 { 276 //token doesn't exist, insert one! 277 $isvalidtoken = false; 278 while ($isvalidtoken == false) 279 { 280 $newtoken = randomChars(15); 281 //ensure same token isn't already in database! 282 283 $query = "SELECT firstname 284 FROM ".$db_value_prefix."tokens_".$sid." 285 WHERE token='".$newtoken."' 286 AND lastname='".$current_user->display_name."' 287 AND email='".$current_user->user_email."'"; 288 289 $temp = $lsdb->get_var( $lsdb->prepare( $query ) ); 290 291 if ( is_null( $temp ) ) 292 { 293 $isvalidtoken = true; 294 } 295 } 296 297 $sanitizedtoken = $newtoken; 298 299 $insert_token = $lsdb->insert( 300 $db_value_prefix.'tokens_'.$sid, 301 array( 302 'firstname' => $current_user->user_login, 303 'lastname' => $current_user->display_name, 304 'email' => $current_user->user_email, 305 'emailstatus' => "OK", 306 'token' => $sanitizedtoken, 307 'language' => $lang, 308 'sent' => 'N', 309 'remindersent' => 'N', 310 'completed' => 'N', 311 'usesleft' => $value_token_uses 312 ), 313 array( 314 '%s', 315 '%s', 316 '%s', 317 '%s', 318 '%s', 319 '%s', 320 '%s', 321 '%s', 322 '%s', 323 '%d' 324 ) 325 ); 326 } 327 328 } 329 330 331 332 } 333 } 334 335 336 337 } 338 339 199 340 //$lsdb = new wpdb( $db_value_user, $db_value_pwd, $db_value_name, $db_value_host ); 200 341 $query = "SELECT a.sid, b.surveyls_title, a.listpublic -
surveypress/trunk/view/option-menu.php
r505547 r540441 9 9 global $apply_option_default_permissions,$show_option_survey_notification,$show_option_import_users,$same_option_password,$list_option_public_surveys; 10 10 global $apply_value_default_permissions,$show_value_survey_notification,$show_value_import_users,$same_value_password,$list_value_public_surveys; 11 global $token_option_sid_list,$token_value_sid_list,$db_value_prefix; 12 global $map_role_subscriber_token,$map_role_administrator_token,$map_role_editor_token,$map_role_author_token,$map_role_contributor_token; 11 global $db_value_prefix; 13 12 global $lsdb; 14 15 16 function randomChars($length,$pattern="23456789abcdefghijkmnpqrstuvwxyz")17 {18 $patternlength = strlen($pattern)-1;19 for($i=0;$i<$length;$i++)20 {21 if(isset($key))22 $key .= $pattern{rand(0,$patternlength)};23 else24 $key = $pattern{rand(0,$patternlength)};25 }26 return $key;27 }28 13 29 14 //output the heading. … … 54 39 $same_value_password = (int) $_POST[ $same_option_password ]; 55 40 $list_value_public_surveys = (int) $_POST[ $list_option_public_surveys ]; 56 $token_value_sid_list = $_POST[ $token_option_sid_list ];41 57 42 58 $map_role_subscriber_token = (int) ( isset($_POST['map_role_subscriber_token']) ) ? ( $_POST['map_role_subscriber_token'] ) : ( 0 );59 $map_role_administrator_token = (int) ( isset($_POST['map_role_administrator_token']) ) ? ( $_POST['map_role_administrator_token'] ) : ( 0 );60 $map_role_editor_token = (int) ( isset($_POST['map_role_editor_token']) ) ? ( $_POST['map_role_editor_token'] ) : ( 0 );61 $map_role_author_token = (int) ( isset($_POST['map_role_author_token']) ) ? ( $_POST['map_role_author_token'] ) : ( 0 );62 $map_role_contributor_token = (int) ( isset($_POST['map_role_contributor_token']) ) ? ( $_POST['map_role_contributor_token'] ) : ( 0 );63 64 43 // Save the posted values in the database 65 44 update_option( $apply_option_default_permissions, $apply_value_default_permissions ); … … 68 47 update_option( $same_option_password, $same_value_password ); 69 48 update_option( $list_option_public_surveys, $list_value_public_surveys ); 70 update_option( $token_option_sid_list, $token_value_sid_list );71 49 72 update_option( 'map_role_subscriber_token', $map_role_subscriber_token );73 update_option( 'map_role_administrator_token', $map_role_administrator_token );74 update_option( 'map_role_editor_token', $map_role_editor_token );75 update_option( 'map_role_author_token', $map_role_author_token );76 update_option( 'map_role_contributor_token', $map_role_contributor_token );77 78 79 //check if $token_option_sid_list is not empty80 if ( $token_value_sid_list != '' || $token_value_sid_list != null )81 {82 $sid_token = explode( ',', $token_value_sid_list );83 84 foreach ($sid_token as $sid)85 {86 $sid = (int) $sid;87 $lang = $lsdb->get_var( $lsdb->prepare( "SELECT language FROM ".$db_value_prefix."surveys WHERE sid=".$sid.";" ) );88 //add tokens for users with specified roles.89 //subscriber90 if((int)$map_role_subscriber_token)91 {92 $users = get_users('role=subscriber');93 foreach ($users as $user) {94 95 $isvalidtoken = false;96 while ($isvalidtoken == false)97 {98 $newtoken = randomChars(15);99 if (!isset($existingtokens[$newtoken]))100 {101 $isvalidtoken = true;102 $existingtokens[$newtoken] = null;103 }104 }105 $sanitizedtoken = $newtoken;106 107 $subscriber = $lsdb->insert(108 $db_value_prefix.'tokens_'.$sid,109 array(110 'firstname' => $user->user_login,111 'lastname' => $user->display_name,112 'email' => $user->user_email,113 'emailstatus' => "OK",114 'token' => $sanitizedtoken,115 'language' => $lang,116 'sent' => 'N',117 'remindersent' => 'N',118 'completed' => 'N',119 'usesleft' => 1120 ),121 array(122 '%s',123 '%s',124 '%s',125 '%s',126 '%s',127 '%s',128 '%s',129 '%s',130 '%s',131 '%d'132 )133 );134 }135 }136 137 //administrator role138 if((int)$map_role_administrator_token)139 {140 $users = get_users('role=administrator');141 foreach ($users as $user) {142 143 $isvalidtoken = false;144 while ($isvalidtoken == false)145 {146 $newtoken = randomChars(15);147 if (!isset($existingtokens[$newtoken]))148 {149 $isvalidtoken = true;150 $existingtokens[$newtoken] = null;151 }152 }153 $sanitizedtoken = $newtoken;154 155 $administrator = $lsdb->insert(156 $db_value_prefix.'tokens_'.$sid,157 array(158 'firstname' => $user->user_login,159 'lastname' => $user->display_name,160 'email' => $user->user_email,161 'emailstatus' => "OK",162 'token' => $sanitizedtoken,163 'language' => $lang,164 'sent' => 'N',165 'remindersent' => 'N',166 'completed' => 'N',167 'usesleft' => 1168 ),169 array(170 '%s',171 '%s',172 '%s',173 '%s',174 '%s',175 '%s',176 '%s',177 '%s',178 '%s',179 '%d'180 )181 );182 }183 }184 185 //editor role186 if((int)$map_role_editor_token)187 {188 $users = get_users('role=editor');189 foreach ($users as $user) {190 191 $isvalidtoken = false;192 while ($isvalidtoken == false)193 {194 $newtoken = randomChars(15);195 if (!isset($existingtokens[$newtoken]))196 {197 $isvalidtoken = true;198 $existingtokens[$newtoken] = null;199 }200 }201 $sanitizedtoken = $newtoken;202 203 $editor = $lsdb->insert(204 $db_value_prefix.'tokens_'.$sid,205 array(206 'firstname' => $user->user_login,207 'lastname' => $user->display_name,208 'email' => $user->user_email,209 'emailstatus' => "OK",210 'token' => $sanitizedtoken,211 'language' => $lang,212 'sent' => 'N',213 'remindersent' => 'N',214 'completed' => 'N',215 'usesleft' => 1216 ),217 array(218 '%s',219 '%s',220 '%s',221 '%s',222 '%s',223 '%s',224 '%s',225 '%s',226 '%s',227 '%d'228 )229 );230 }231 }232 233 //author role234 if((int)$map_role_author_token)235 {236 $users = get_users('role=author');237 foreach ($users as $user) {238 239 $isvalidtoken = false;240 while ($isvalidtoken == false)241 {242 $newtoken = randomChars(15);243 if (!isset($existingtokens[$newtoken]))244 {245 $isvalidtoken = true;246 $existingtokens[$newtoken] = null;247 }248 }249 $sanitizedtoken = $newtoken;250 251 $author = $lsdb->insert(252 $db_value_prefix.'tokens_'.$sid,253 array(254 'firstname' => $user->user_login,255 'lastname' => $user->display_name,256 'email' => $user->user_email,257 'emailstatus' => "OK",258 'token' => $sanitizedtoken,259 'language' => $lang,260 'sent' => 'N',261 'remindersent' => 'N',262 'completed' => 'N',263 'usesleft' => 1264 ),265 array(266 '%s',267 '%s',268 '%s',269 '%s',270 '%s',271 '%s',272 '%s',273 '%s',274 '%s',275 '%d'276 )277 );278 }279 }280 281 //contributor role282 if((int)$map_role_contributor_token)283 {284 $users = get_users('role=contributor');285 foreach ($users as $user) {286 287 $isvalidtoken = false;288 while ($isvalidtoken == false)289 {290 $newtoken = randomChars(15);291 if (!isset($existingtokens[$newtoken]))292 {293 $isvalidtoken = true;294 $existingtokens[$newtoken] = null;295 }296 }297 $sanitizedtoken = $newtoken;298 299 $contributor = $lsdb->insert(300 $db_value_prefix.'tokens_'.$sid,301 array(302 'firstname' => $user->user_login,303 'lastname' => $user->display_name,304 'email' => $user->user_email,305 'emailstatus' => "OK",306 'token' => $sanitizedtoken,307 'language' => $lang,308 'sent' => 'N',309 'remindersent' => 'N',310 'completed' => 'N',311 'usesleft' => 1312 ),313 array(314 '%s',315 '%s',316 '%s',317 '%s',318 '%s',319 '%s',320 '%s',321 '%s',322 '%s',323 '%d'324 )325 );326 }327 }328 }329 330 331 }332 333 $token_msg = '';334 if ( $token_value_sid_list != '' || $token_value_sid_list != null )335 {336 //construct new message!337 $token_msg = " Tokens added for users with roles :";338 if( (int)$map_role_subscriber_token )339 {340 $token_msg .= " Subscriber";341 }342 if( (int)$map_role_administrator_token )343 {344 $token_msg .= " Administrator";345 }346 if( (int)$map_role_editor_token )347 {348 $token_msg .= " Editor";349 }350 if( (int)$map_role_author_token )351 {352 $token_msg .= " Author";353 }354 if( (int)$map_role_contributor_token )355 {356 $token_msg .= " Contributor";357 }358 $token_msg .=" in survey(s) with surveyid(s) :";359 360 $sid_token = explode( ',', $token_value_sid_list );361 foreach ( $sid_token as $sid )362 {363 $token_msg .= " ".$sid;364 }365 366 $token_msg .=".";367 }368 369 //unset values;370 $token_value_sid_list = '';371 $map_role_subscriber_token = 0;372 $map_role_administrator_token = 0;373 $map_role_editor_token = 0;374 $map_role_author_token = 0;375 $map_role_contributor_token = 0;376 377 update_option( $token_option_sid_list, $token_value_sid_list );378 379 update_option( 'map_role_subscriber_token', $map_role_subscriber_token );380 update_option( 'map_role_administrator_token', $map_role_administrator_token );381 update_option( 'map_role_editor_token', $map_role_editor_token );382 update_option( 'map_role_author_token', $map_role_author_token );383 update_option( 'map_role_contributor_token', $map_role_contributor_token );384 50 // Put an settings updated message on the screen 385 51 … … 388 54 <div class='updated'> 389 55 <p><strong><?php _e('Settings saved.', 'menu-test' ); 390 if ( $token_msg != '' ) echo $token_msg; ?></strong></p> 56 ?> 57 </strong></p> 391 58 </div> 392 59 … … 475 142 </tr> 476 143 477 <tr valign="top"> 478 <th scope="row"> 479 <?php _e("Add token for users with following roles:", 'menu-test' ); ?> 480 </th> 481 <td> 482 <p> 483 <label> 484 <input type="checkbox" name="map_role_subscriber_token" value="1" <?php if((int)$map_role_subscriber_token) { ?> checked="checked" <?php } ?> /> 485 <?php _e("Subscriber"); ?> 486 </label> 487 488 <label> 489 <input type="checkbox" name="map_role_administrator_token" value="1" <?php if((int)$map_role_administrator_token) { ?> checked="checked" <?php } ?> /> 490 <?php _e("Administrator"); ?> 491 </label> 492 493 <label> 494 <input type="checkbox" name="map_role_editor_token" value="1" <?php if((int)$map_role_editor_token) { ?> checked="checked" <?php } ?> /> 495 <?php _e("Editor"); ?> 496 </label> 497 498 <label> 499 <input type="checkbox" name="map_role_author_token" value="1" <?php if((int)$map_role_author_token) { ?> checked="checked" <?php } ?> /> 500 <?php _e("Author"); ?> 501 </label> 502 503 <label> 504 <input type="checkbox" name="map_role_contributor_token" value="1" <?php if((int)$map_role_contributor_token) { ?> checked="checked" <?php } ?> /> 505 <?php _e("Contributor"); ?> 506 </label> 507 <br /> 508 <b><?php _e("In surveys with surveyid:"); ?></b><br /> 509 <input type="text" name="<?php echo $token_option_sid_list; ?>" id="<?php echo $token_option_sid_list; ?>" value="<?php echo $token_value_sid_list; ?>" size="20" class="regular-text" /> 510 <span class="description">( Comma(,) separated list of surveyid(s) for which tokens must be added to there respective tables. )</span> 511 <br /><span class="description">( Users with checked role(s) will have a token each in specified surveys above. Token added can be used only once! )</span> 512 513 </p> 514 </td> 515 </tr> 516 144 517 145 <tr valign="top"> 518 146 <th scope="row">
Note: See TracChangeset
for help on using the changeset viewer.