Changeset 3156554
- Timestamp:
- 09/24/2024 12:14:06 AM (18 months ago)
- File:
-
- 1 edited
-
simple-student-result/trunk/activation.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
simple-student-result/trunk/activation.php
r3156553 r3156554 1 1 <?php 2 register_activation_hook(SSR_ROOT_FILE,'ssr_plugin_install'); 3 function ssr_plugin_install(){ 4 global $wpdb;$table_name=$wpdb->prefix.'ssr_studentinfo'; 5 if($wpdb->get_var("SHOW TABLES LIKE '$table_name'")!=$table_name){ 6 $charset_collate = $wpdb->get_charset_collate(); 7 $sql = "CREATE TABLE $table_name ( 8 rid varchar(100) NOT NULL, 9 roll text NULL, 10 stdname text NULL, 11 fathersname text NULL, 12 pyear text NULL, 13 cgpa text NULL, 14 subject text NULL, 15 image text NULL, 16 dob text NULL, 17 gender text NULL, 18 address text NULL, 19 mnam text NULL, 20 c1 text NULL, 21 c2 text NULL, 22 UNIQUE KEY id (rid) 23 ) $charset_collate;"; 2 24 3 register_activation_hook(__FILE__, 'ssr_plugin_install'); 4 function ssr_plugin_install(){ 5 global $wpdb; 6 $table_name = $wpdb->prefix . 'ssr_studentinfo'; 7 8 // Check if the table exists 9 if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { 10 $charset_collate = $wpdb->get_charset_collate(); 11 $sql = "CREATE TABLE $table_name ( 12 rid varchar(100) NOT NULL, 13 roll text NULL, 14 stdname text NULL, 15 fathersname text NULL, 16 pyear text NULL, 17 cgpa text NULL, 18 subject text NULL, 19 image text NULL, 20 dob text NULL, 21 gender text NULL, 22 address text NULL, 23 mnam text NULL, 24 c1 text NULL, 25 c2 text NULL, 26 UNIQUE KEY id (rid) 27 ) $charset_collate;"; 28 29 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 30 dbDelta($sql); 31 32 // Setting up initial posts 33 for ($i = 1; $i <= 3; $i++) { 34 $my_post = array( 35 'post_type' => 'ssr_subjects', 36 'post_title' => 'Subject ' . $i, 37 'post_content' => 'This is Subject ' . $i, 38 'post_status' => 'publish', 39 'post_author' => 1 40 ); 41 wp_insert_post($my_post); 42 } 43 44 $cgpa = 2.50; 45 while ($cgpa <= 5.5) { 46 $my_post = array( 47 'post_type' => 'ssr_cgpa', 48 'post_title' => number_format($cgpa, 2), 49 'post_content' => 'This is description of cgpa ' . number_format($cgpa, 2), 50 'post_status' => 'publish', 51 'post_author' => 1 52 ); 53 wp_insert_post($my_post); 54 $cgpa += 0.25; 55 } 56 57 // Update the plugin version 58 update_option('ssr_version_installed', SSR_VERSION); 59 } 60 ssr_db_update_from_138(); 61 do_action('plugins_loaded'); 25 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 26 dbDelta( $sql ); 27 add_option('jal_db_version',$jal_db_version);if(WP_CACHE&&function_exists('wp_cache_postload'))wp_cache_postload();wp_functionality_constants();$wp_the_query=new WP_Query();$wp_query=&$wp_the_query;$GLOBALS['wp_rewrite']=new WP_Rewrite();$i=1;while($i<=3){$my_post=array('post_type'=>'ssr_subjects','post_title'=>'Subject '.$i.'','post_content'=>'This is Subject '.$i.'','post_status'=>'publish','post_author'=>1);wp_insert_post($my_post);$i++;}$i=1;$cgpa=2.50;number_format($cgpa,2);while($cgpa<=5.5){$my_post=array('post_type'=>'ssr_cgpa','post_title'=>number_format($cgpa,2),'post_content'=>'This is description of cgpa '.number_format($cgpa,2).'','post_status'=>'publish','post_author'=>1);wp_insert_post($my_post);$i++;$cgpa=$cgpa+.25;} 28 } 29 ssr_db_update_from_138();do_action('plugins_loaded'); 30 } 31 register_uninstall_hook(SSR_ROOT_FILE,'ssr_unins'); 32 function ssr_unins(){ 33 global $wpdb; 34 $table = $wpdb->prefix.SSR_TABLE; 35 delete_option('ssr_settings_ssr_item1');delete_option('ssr_settings_ssr_item2');delete_option('ssr_settings_ssr_item3');delete_option('ssr_settings_ssr_item4');delete_option('ssr_settings_ssr_item5');delete_option('ssr_settings_ssr_item6');delete_option('ssr_settings_ssr_item7');delete_option('ssr_settings_ssr_item8');delete_option('ssr_settings_ssr_item9');delete_option('ssr_settings_ssr_item10');delete_option('ssr_settings_ssr_item11');delete_option('ssr_settings_ssr_item12');delete_option('ssr_settings_ssr_item13');delete_option('ssr_settings_ssr_item14'); 36 $wpdb->query("DROP TABLE IF EXISTS $table"); 37 } 38 function ssr_ihh_check_version(){ 39 if (esc_attr( get_option('ssr_version_installed') )!=SSR_VERSION){ 40 ssr_set_d_v(); 41 ssr_db_update_from_138(); 42 } 62 43 } 63 64 register_uninstall_hook(__FILE__, 'ssr_unins'); 65 function ssr_unins(){ 66 global $wpdb; 67 $table = $wpdb->prefix . 'ssr_studentinfo'; 68 69 // Delete related options 70 for ($i = 1; $i <= 21; $i++) { 71 delete_option('ssr_settings_ssr_item' . $i); 72 } 73 74 // Drop the table 75 $wpdb->query("DROP TABLE IF EXISTS $table"); 76 } 77 78 add_action('plugins_loaded', 'ssr_ihh_check_version'); 79 function ssr_ihh_check_version(){ 80 if (get_option('ssr_version_installed') != SSR_VERSION) { 81 ssr_set_d_v(); 82 ssr_db_update_from_138(); 83 } 84 } 44 add_action( 'plugins_loaded', 'ssr_ihh_check_version' ); 85 45 86 46 function ssr_set_d_v(){ 87 if (defined('SSR_VERSION_B') && SSR_VERSION_B <= 143) { 88 global $wpdb; 89 $table = $wpdb->prefix . 'ssr_studentinfo'; 90 91 $wpdb->query("ALTER TABLE $table CHANGE rid rid varchar(100) NOT NULL"); 92 $wpdb->query("ALTER TABLE $table CHANGE stdname stdname text NULL"); 93 $wpdb->query("ALTER TABLE $table CHANGE fathersname fathersname text NULL"); 94 $wpdb->query("ALTER TABLE $table CHANGE subject subject text NULL"); 95 $wpdb->query("ALTER TABLE $table CHANGE image image text NULL"); 96 $wpdb->query("ALTER TABLE $table CHANGE dob dob text NULL"); 97 $wpdb->query("ALTER TABLE $table CHANGE gender gender text NULL"); 98 $wpdb->query("ALTER TABLE $table CHANGE roll roll text NULL"); 99 $wpdb->query("ALTER TABLE $table CHANGE pyear pyear text NULL"); 100 $wpdb->query("ALTER TABLE $table CHANGE address address text NULL"); 101 $wpdb->query("ALTER TABLE $table CHANGE cgpa cgpa text NULL"); 102 $wpdb->query("ALTER TABLE $table CHANGE c1 c1 text NULL"); 103 $wpdb->query("ALTER TABLE $table CHANGE c2 c2 text NULL"); 104 $wpdb->query("ALTER TABLE $table CHANGE mnam mnam text NULL"); 105 } 106 107 update_option('ssr_version_installed', SSR_VERSION); 47 if (SSR_VERSION_B<=143){ 48 global $wpdb; 49 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE rid rid varchar(100) NOT NULL"); 50 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE stdname stdname text NULL"); 51 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE fathersname fathersname text NULL"); 52 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE subject subject text NULL"); 53 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE image image text NULL"); 54 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE dob dob text NULL"); 55 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE gender gender text NULL"); 56 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE roll roll text NULL"); 57 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE pyear pyear text NULL"); 58 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE address address text NULL"); 59 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE cgpa cgpa text NULL"); 60 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE c1 c1 text NULL"); 61 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE c2 c2 text NULL"); 62 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." CHANGE mnam mnam text NULL"); 63 } 64 update_option('ssr_version_installed',SSR_VERSION); 108 65 } 109 66 110 67 function ssr_db_update_from_138(){ 111 global $wpdb; 112 $table = $wpdb->prefix . 'ssr_studentinfo'; 68 global $wpdb; 69 $row = $wpdb->get_results( "SELECT * FROM information_schema.COLUMNS 70 WHERE TABLE_SCHEMA = '".DB_NAME."' AND TABLE_NAME = '".$wpdb->prefix.SSR_TABLE."' AND COLUMN_NAME = 'address'" ); 113 71 114 $columns = $wpdb->get_results("SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '".DB_NAME."' AND TABLE_NAME = '$table'", ARRAY_A); 115 $columns = array_column($columns, 'COLUMN_NAME'); 116 117 $fields = ['dob', 'gender', 'address', 'mnam', 'c1', 'c2']; 118 foreach ($fields as $field) { 119 if (!in_array($field, $columns)) { 120 $wpdb->query("ALTER TABLE $table ADD $field text NULL"); 121 } 122 } 72 if(empty($row)){ 73 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." ADD dob text NULL"); 74 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." ADD gender text NULL"); 75 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." ADD address text NULL"); 76 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." ADD mnam text NULL"); 77 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." ADD c1 text NULL"); 78 $wpdb->query("ALTER TABLE ".$wpdb->prefix.SSR_TABLE." ADD c2 text NULL"); 123 79 } 124 125 // Set default options if not set126 for ($i = 1; $i <= 21; $i++) {127 $option_name = 'ssr_settings_ssr_item' . $i;128 if (strlen(esc_attr(get_option($option_name))) == 0) {129 update_option($option_name, 'Default value for item ' . $i);130 }131 80 } 132 81 if (strlen(esc_attr( get_option('ssr_settings_ssr_item1') ))==0) update_option('ssr_settings_ssr_item1','Online Result System'); 82 if (strlen(esc_attr( get_option('ssr_settings_ssr_item2') ))==0) update_option('ssr_settings_ssr_item2','Enter Registration ID'); 83 if (strlen(esc_attr( get_option('ssr_settings_ssr_item3') ))==0) update_option('ssr_settings_ssr_item3','No Results !'); 84 if (strlen(esc_attr( get_option('ssr_settings_ssr_item4') ))==0) update_option('ssr_settings_ssr_item4','Student'); 85 if (strlen(esc_attr( get_option('ssr_settings_ssr_item5') ))==0) update_option('ssr_settings_ssr_item5','Students Result'); 86 if (strlen(esc_attr( get_option('ssr_settings_ssr_item6') ))==0) update_option('ssr_settings_ssr_item6','Add Student Results'); 87 if (strlen(esc_attr( get_option('ssr_settings_ssr_item7') ))==0) update_option('ssr_settings_ssr_item7','CGPA'); 88 if (strlen(esc_attr( get_option('ssr_settings_ssr_item8') ))==0) update_option('ssr_settings_ssr_item8','Subject'); 89 if (strlen(esc_attr( get_option('ssr_settings_ssr_item9') ))==0) update_option('ssr_settings_ssr_item9','Registration Number'); 90 if (strlen(esc_attr( get_option('ssr_settings_ssr_item10') ))==0) update_option('ssr_settings_ssr_item10','Roll No'); 91 if (strlen(esc_attr( get_option('ssr_settings_ssr_item11') ))==0) update_option('ssr_settings_ssr_item11','Student Name'); 92 if (strlen(esc_attr( get_option('ssr_settings_ssr_item12') ))==0) update_option('ssr_settings_ssr_item12','Fathers Name'); 93 if (strlen(esc_attr( get_option('ssr_settings_ssr_item13') ))==0) update_option('ssr_settings_ssr_item13','Passing Year'); 94 if (strlen(esc_attr( get_option('ssr_settings_ssr_item14') ))==0) update_option('ssr_settings_ssr_item14','CGPA'); 95 if (strlen(esc_attr( get_option('ssr_settings_ssr_item15') ))==0) update_option('ssr_settings_ssr_item15','Subject'); 96 if (strlen(esc_attr( get_option('ssr_settings_ssr_item16') ))==0) update_option('ssr_settings_ssr_item16','Extra Field 1'); 97 if (strlen(esc_attr( get_option('ssr_settings_ssr_item17') ))==0) update_option('ssr_settings_ssr_item17','Extra Field 2'); 98 if (strlen(esc_attr( get_option('ssr_settings_ssr_item18') ))==0) update_option('ssr_settings_ssr_item18','Extra Field 3'); 99 if (strlen(esc_attr( get_option('ssr_settings_ssr_item19') ))==0) update_option('ssr_settings_ssr_item19','Extra Field 4'); 100 if (strlen(esc_attr( get_option('ssr_settings_ssr_item20') ))==0) update_option('ssr_settings_ssr_item20','Extra Field 5'); 101 if (strlen(esc_attr( get_option('ssr_settings_ssr_item21') ))==0) update_option('ssr_settings_ssr_item21','Extra Field 6'); 102 // if (strlen(esc_attr( get_option('ssr_settings_ssr_item22') ))==0) update_option('ssr_settings_ssr_item21','Extra Fields 3'); 133 103 ?>
Note: See TracChangeset
for help on using the changeset viewer.