예제 #1
0
$transactions = $parser->getTransactions($bank, $user, $pass);
?>

<?php 
function convert_to_csv($input_array, $output_file_name, $delimiter)
{
    /** open raw memory as file, no need for temp files, be careful not to run out of memory thought */
    $f = fopen('php://memory', 'w');
    /** loop through array  */
    foreach ($input_array as $line) {
        /** default php csv handler **/
        fputcsv($f, $line, $delimiter);
    }
    /** rewrind the "file" with the csv lines **/
    fseek($f, 0);
    /** modify header to be downloadable csv file **/
    header('Content-Type: application/csv');
    header('Content-Disposition: attachement; filename="' . $output_file_name . '";');
    /** Send file to browser for download */
    fpassthru($f);
}
?>

<?php 
/** Array to convert to csv */
$array_to_csv = $transactions;
convert_to_csv($array_to_csv, 'reportku1.csv', ',');
?>

<?php 
ob_end_flush();
예제 #2
0
        //explain the error
        echo "<div id='error'>something not right. " . $postcode . " Doesn't have an entry in the CSV file. It shipped via hermes reference: " . $fuldata[$postcode] . "</div>";
        //if anything goes wrong with the csv
        if (!array_key_exists($postcode, $fuldata)) {
            //add to errors
            $htmlerrors++;
            //explain the error
            echo "<div id='error'>something not right. " . $postcode . " Doesn't have an entry in the HTML file. Was it Shipped via Hermes?: " . $fulcsv[$postcode] . "</div>";
        }
    } else {
        //        echo "<div id='output'><spanid='first'>Output:" . $postcode . "</span><span id='second'> " . $fulcsv[$postcode] . "</span><span id='third'>" . $fuldata[$postcode] . "</span></div>";
        //build an array of the order reference from the csv file
        //and shipping reference from the html file
        //that match each other through the postcode
        $list[] = array($fulcsv[$postcode], $fuldata[$postcode]);
    }
    //count of total number of entries
    $errorcorr++;
}
//	var_dump ($list);
//if there are still no errors then
if ($csverrors == 0 && $htmlerrors == 0) {
    //output a csv wiith the array using the convert_to_csv function
    convert_to_csv($list, 'report.csv', ',');
} else {
    //otherwise dump the results along with the content above to
    echo "<p>no file until corrections have been corrected";
    echo "<p>Total Entries  " . $errorcorr;
    echo "<p>csv errors  " . $csverrors;
    echo "<p>html errors  " . $htmlerrors;
}
예제 #3
0
파일: download.php 프로젝트: CNCFlora/sig
    }
    // If there is still any occurrence not validated for that specie,
    // can't download CSV
    if ($d->not_validated > 0) {
        $occ_miss = $d->not_validated;
        $msg_alerta = $msg_alerta . "Espécie <b>{$specie}</b> ainda não foi inteiramente validada. Falta(m) <b>{$occ_miss}</b> registro(s) de ocorrência.<br>";
        $can_download = false;
    } elseif (count($occurrences) == 0) {
        $msg_warning = $msg_warning . "Não foram encontradas ocorrências para a espécie <b>{$specie}</b>.<br>";
    } elseif ($d->valid == 0 && $d->invalid > 0) {
        $msg_warning = $msg_warning . "Todas as ocorrências para a espécie <b>{$specie}</b> são inválidas.<br>";
    } elseif ($d->precision_nok > 0) {
        $occ_precision = $d->precision_nok;
        $msg_alerta = $msg_alerta . "Espécie <b>{$specie}</b> possui <b>{$occ_precision}</b> ocorrência(s) com precisão fora do padrão.<br />";
        $can_download = false;
    } else {
        $csv_array = array_merge($csv_array, $row);
    }
}
if ($can_download && count($csv_array) > 0) {
    //Add header as first row
    $columns = ["id", "specieID", "family", "specie", "inst_code", "col_code", "catalog_n", "recordedby", "record_n", "year", "month", "day", "state", "city", "locality", "longitude", "latitude", "precision", "protocol"];
    array_unshift($csv_array, $columns);
    //convert_to_csv($csv_array, "sig_$name.csv", ',');
    convert_to_csv($csv_array, "sig_{$name}.csv", ';');
} else {
    $_SESSION['msg_alerta'] = $msg_alerta;
    $_SESSION['msg_warning'] = $msg_warning;
    session_write_close();
    header("Location: index.php");
}
function savedquest_options()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    echo '<div class="wrap" style="background:#fff;">';
    if (isset($_GET['tab'])) {
        $tab = $_GET['tab'];
    } else {
        $tab = "";
    }
    saved_admin_tab($tab);
    if ($tab == "quiztaken" or $tab == "") {
        ?>

		<table  class="wp-list-table widefat fixed striped pages" width="100%" style="border-spacing: 0; text-align:center;" >
			<tr>
				<th>Lesson ID</th>
				<th>Lesson Title</th>
				<th>Number Of Questions</th>
				<th>Question Answered</th>
				<th>Unanswered Question</th>
				<th>User</th>
				<th>User Id</th>
				<th>DATE And Time</th>
			</tr>
			<?php 
        $svequiz = get_option('savequiz_list');
        ?>

			<?php 
        foreach ($svequiz as $quizdata) {
            ?>

			<tr>
				<td><?php 
            echo $quizdata['lesson_id'];
            ?>
</td> 	
				<td><?php 
            echo $quizdata['lesson_title'];
            ?>
</td> 
				<td><?php 
            echo $quizdata['total_questtion'];
            ?>
</td> 
				<td><?php 
            echo $quizdata['question_answered'];
            ?>
(<?php 
            echo get_percentage($quizdata['total_questtion'], $quizdata['question_answered']) . "%";
            ?>
)</td> 
				<td><?php 
            echo $quizdata['remaining_question'];
            ?>
(<?php 
            echo 100 - get_percentage($quizdata['total_questtion'], $quizdata['question_answered']) . "%";
            ?>
)</td> 
				<td><?php 
            echo $quizdata['fullname'];
            ?>
</td>		
				<td><?php 
            echo $quizdata['user_id'];
            ?>
 </td>				
				<td><?php 
            echo $quizdata['DATETIME'];
            ?>
</td> 				
			</tr>
			<?php 
        }
        ?>

		</table>
		
	<?php 
    } elseif ($tab == "timesession") {
        $user_last_login_logout = get_option('user_last_login_logout');
        ?>

	<br /><br/>
		<table  class="wp-list-table widefat fixed striped pages" width="100%" style="border-spacing: 0; text-align:center;" >
			<tr>
				<th>User ID</th>
				<th>Full Name</th>
				<th>Last Login</th>
				<th>Last Logout</th>
				<th>Amout of Time Spent</th>
				<th>Role</th>

			</tr>
			<?php 
        $svequiz = get_option('savequiz_list');
        ?>

			<?php 
        foreach ($user_last_login_logout as $last_login_logout) {
            ?>

			<?php 
            if ($last_login_logout['user_id'] != "") {
                ?>

			<?php 
                $user_info = get_userdata($last_login_logout['user_id']);
                ?>

			<tr>
				<td><?php 
                echo $last_login_logout['user_id'];
                ?>
</td> 
				<td><?php 
                echo $user_info->display_name;
                ?>
</td> 					
				<td><?php 
                echo gettime_st($last_login_logout['logintime']);
                ?>
</td> 
				<td><?php 
                echo gettime_st($last_login_logout['logouttime']);
                ?>
</td> 
				<?php 
                if ($last_login_logout['logouttime'] != "") {
                    $date1 = date_create($last_login_logout['logintime']);
                    $date2 = date_create($last_login_logout['logouttime']);
                    $diff = date_diff($date1, $date2);
                    $diftime = $diff->format("%h Hours %i Minute %s Seconds");
                } else {
                    $diftime = "";
                }
                ?>

				
				<th><?php 
                echo $diftime;
                ?>
</th>
				<td><?php 
                echo implode(', ', $user_info->roles);
                ?>
</td>
		
			</tr>
			<?php 
            }
            ?>

			<?php 
        }
        ?>

		</table><br /><br />


	<?php 
    } elseif ($tab == "timequizecompleted") {
        global $woothemes_sensei, $post, $current_user, $wp_query, $learner_user;
        echo "<table class='wp-list-table widefat fixed striped pages'>";
        $allUsers = get_users();
        echo "<tr>\r\r\n\t\t\t\t<th>User</th>\r\r\n\t\t\t\t<th>Courses</th>\r\r\n\t\t\t\t<th>Percentage Incomplete</th>\r\r\n\t\t\t\t<th>Percentage Complete</th>\r\r\n\t\t\t\t<th>Percentage Competent</th>\r\r\n\t\t\t\t<th>Percentage Attempted</th>\r\r\n\t\t\t\t<th>Length of time Course Completed</th>\r\r\n\t\t\t  </tr>";
        foreach ($allUsers as $user) {
            $args = array('post_type' => 'course');
            $courses = get_posts($args);
            $i = 1;
            foreach ($courses as $course) {
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($course->ID, $user->ID);
                $course_status = WooThemes_Sensei_Utils::user_course_status($course->ID, $user->ID);
                $course_status_update = get_comment_meta($course_status->comment_ID);
                if (!empty($course_status)) {
                    $displayed_lessons = array();
                    $modules = Sensei()->modules->get_course_modules(intval($course->ID));
                    foreach ($modules as $module) {
                        $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0);
                        $lessons = get_posts($args);
                        if (count($lessons) > 0) {
                            $html .= '<h3>' . $module->name . '</h3>' . "\n";
                            $count = 0;
                            foreach ($lessons as $lesson_item) {
                                $lesson_grade = ' n/a';
                                $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true);
                                if ($has_questions) {
                                    $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID);
                                    // Get user quiz grade
                                    $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
                                    if ($lesson_grade) {
                                        $lesson_grade .= '%';
                                    }
                                    $modulequizdata = get_comment_meta($lesson_status->comment_ID);
                                    //echo "<a href='".get_post_permalink($lesson_item->ID)."'>".$lesson_item->post_title."</a><br />";
                                    $modulequestion_asked = count(explode(",", $modulequizdata['questions_asked'][0]));
                                    $moduleanswered_quiz = count(unserialize($modulequizdata['quiz_answers'][0]));
                                    //echo "number of questions:".$modulequestion_asked."<br />";
                                    //echo "number of Answered:".$moduleanswered_quiz."<br />";
                                    if ($course_status->comment_approved == "complete") {
                                        $attempted = "(100%)";
                                    } else {
                                        if ($modulequizdata['grade'][0] == "") {
                                            if ($lesson_status->comment_approved == "passed") {
                                                $attempted = 'P/Q';
                                            } else {
                                                if ($modulequestion_asked >= $moduleanswered_quiz) {
                                                    if ($modulequizdata['quiz_answers'][0] == "") {
                                                        $attempted = "";
                                                    } else {
                                                        $attempted = "( " . get_percentage($modulequestion_asked, $moduleanswered_quiz) . "% ) Saved";
                                                    }
                                                }
                                            }
                                        } else {
                                            $attempted = "( " . get_percentage($modulequestion_asked, $moduleanswered_quiz) . "% )";
                                        }
                                        //echo "<pre>";
                                        //echo "Attempted:".$attempted."<br />";
                                        //echo $user->user_email."<br />";
                                        //echo $modulequizdata['grade'][0]."<br />";
                                        //echo $modulequizdata['quiz_answers'][0]."<br />";
                                        //print_r($lesson_status);
                                        //echo "</pre>";
                                    }
                                }
                                $html .= '<a href="' . esc_url(get_permalink($lesson_item->ID)) . '" title="' . esc_attr(sprintf(__('Start %s', 'woothemes-sensei'), $lesson_item->post_title)) . '">' . esc_html(sprintf(__('%s', 'woothemes-sensei'), $lesson_item->post_title)) . '</a> ' . $attempted . '<br />';
                                $displayed_lessons[] = $lesson_item->ID;
                            }
                        }
                    }
                    $args = array('post_type' => 'lesson', 'posts_per_page' => -1, 'suppress_filters' => 0, 'meta_key' => '_order_' . $course->ID, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID))), 'post__not_in' => $displayed_lessons);
                    $lessons = get_posts($args);
                    //echo "Number of lesson in a course: ".count($lessons);
                    if (0 < count($lessons)) {
                        $html .= '<h3>' . __('Other Lessons', 'woothemes-sensei') . '</h3>' . "\n";
                    }
                    if ($course_status_update['percent'][0] == 100) {
                        $date1 = date_create($course_status_update['start'][0]);
                        $date2 = date_create($course_status->comment_date);
                        $diff = date_diff($date1, $date2);
                        $diftime = $diff->format("%h Hours %i Minute %s Seconds");
                    } else {
                        $diftime = "course not completed yet.";
                    }
                    $allcourseid[] = $course->ID;
                    $incomplete = 100 - $course_status_update['percent'][0];
                    echo "<tr><td>";
                    echo $user->user_email;
                    echo "</td>";
                    echo "<td>";
                    echo "<a href='" . get_post_permalink($course->ID) . "'>" . $course->post_title . "</a>";
                    echo "</td>";
                    echo "<td>";
                    echo $incomplete . "%";
                    echo "</td>";
                    echo "<td>";
                    echo $course_status_update['percent'][0] . "%";
                    echo "</td>";
                    echo "<td>";
                    echo $course_user_grade . "%";
                    echo "</td>";
                    echo "<td>";
                    echo $html;
                    $html = "";
                    foreach ($lessons as $lesson_item) {
                        $lesson_grade = 'n/a';
                        $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true);
                        if ($has_questions) {
                            $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID);
                            // Get user quiz grade
                            $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
                            if ($lesson_grade) {
                                $lesson_grade .= '%';
                            }
                        }
                        $quizdata = get_comment_meta($lesson_status->comment_ID);
                        //echo "<h1>Comment</h1>";
                        //print_r(get_comment_meta( $lesson_status->comment_ID ));
                        //echo "<h1>LESSON STATUS</h1>";
                        //print_r($lesson_status);
                        echo "<a href='" . get_post_permalink($lesson_item->ID) . "'>" . $lesson_item->post_title . "</a> ";
                        //print_r($quizdata);
                        $question_asked = count(explode(",", $quizdata['questions_asked'][0]));
                        $answered_quiz = count(unserialize($quizdata['quiz_answers'][0]));
                        if ($quizdata['grade'][0] == "") {
                            if ($question_asked > $answered_quiz) {
                                echo "( " . get_percentage($question_asked, $answered_quiz) . "% )";
                            }
                        } else {
                            echo "(100%)";
                        }
                        echo '<br />';
                    }
                    // End For Loop
                    echo "</td>";
                    echo "<td>";
                    echo $diftime;
                    echo "</td>";
                    echo "</tr>";
                    //echo $course->post_title." (".$course_status_update['percent'][0]."% Complete) (". $incomplete . "% incomplete) (". $course_user_grade . "% Competent)<br />";
                    $i++;
                }
            }
        }
        echo "</table>";
    } elseif ($tab == "threshold") {
        //declare the wpdb for custom query
        global $wpdb;
        //check for submitted data
        if (isset($_POST['submittreshold']) && ($_POST['submittreshold'] = "submit")) {
            // declare users and variables
            $allUsers = get_users();
            $modules_completed = $_POST['completionpermonth'];
            $courseid = $_POST['course'];
            $course_name = get_the_title($courseid);
            $array_to_csv = array(array('Student Name', 'Course Name '));
            //user loop ----- loop user get the groups and course the course they take
            foreach ($allUsers as $user) {
                //declare course function calls
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->ID);
                $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->ID);
                $course_status_info = get_comment_meta($user_course_status->comment_ID);
                $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->ID);
                $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->ID);
                $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status);
                //get the user groups
                $useringroup = new Groups_User($user->ID);
                $user_groups = $useringroup->__get('groups');
                $displayed_lessons = array();
                //declare and get module values
                $modules = Sensei()->modules->get_course_modules(intval($courseid));
                $modules_content = Sensei()->modules->course_module_content(intval($courseid));
                //echo "<pre>";
                //echo $user->user_email."<br />";
                //echo "sensei_user_course_status_message: ";
                //print_r($course_status);
                //echo "<br />";
                //echo "started_course: "."<br />";
                $course_status_info['start'][0];
                $datenow = date('Y-m-d h:i:s');
                $date1 = date_create($course_status_info['start'][0]);
                $date2 = date_create($datenow);
                $diff = date_diff($date1, $date2);
                $diftime = $diff->format("%m");
                if ($diftime < 1) {
                    $diftime = 1;
                }
                //echo "</pre>";
                //module loop per user
                foreach ($modules as $module) {
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($courseid), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0);
                    $lessons = get_posts($args);
                    $num_of_lesson = count($lessons);
                    //lessson loop per user
                    foreach ($lessons as $lesson_item) {
                        $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $user->ID);
                        if ($is_lesson_completed == 1) {
                            $lesson_completed[] = $is_lesson_completed;
                        }
                    }
                    //echo "lesson completed:". count($lesson_completed)."<br />";
                    if (count($lesson_completed) > 0) {
                        if ($num_of_lesson == count($lesson_completed)) {
                            $completed_modules_per_user[] = 1;
                            $total_module_passed[] = 1;
                            //echo "---Module completed <br />";
                        } else {
                            //echo "---Module not completed <br />";
                        }
                    } else {
                        //echo "---Module not completed <br />";
                    }
                    unset($lesson_completed);
                    unset($completed_modules_per_user);
                }
                $overaalltotal_module_passed = count($total_module_passed);
                //echo $overaalltotal_module_passed . " module being passed";
                //loop throughout the user group under a user
                if (is_array($user_groups)) {
                    foreach ($user_groups as $user_group) {
                        if ($user_group->group_id == $_POST['group']) {
                            if (!empty($user_course_status)) {
                                $modules_completed_from_groups = $user_group->description;
                                if ($modules_completed == "") {
                                    $modules_completed = $modules_completed_from_groups;
                                }
                                $num_of_module_x_difftime = $modules_completed * $diftime;
                                //echo "<br />num_of_module_x_difftime:".$num_of_module_x_difftime;
                                if ($overaalltotal_module_passed >= $num_of_module_x_difftime) {
                                    $array_to_csv[] = array($user->display_name, $course_name);
                                    //$userid_within_group[$user->user_email] = $user->ID;
                                }
                            }
                        }
                        //echo $user_group->group_id."<br />";
                    }
                }
                unset($total_module_passed);
            }
            //echo "<pre>";
            //echo $modules_completed;
            //print_r($array_to_csv);
            //echo "</pre>";
            convert_to_csv($array_to_csv, 'report-' . md5(date('Y-m-d h:i:s')) . '.csv', ',');
        }
        ?>
		<div class="form-wrap" style="padding:20px;">
			<form action="" method="post">
				
				<div>
					<label>
						Group:
					</label>
						<?php 
        $groups = $wpdb->get_results('SELECT * FROM `wp_groups_group`');
        ?>
					
					<select name="group">
						<?php 
        foreach ($groups as $group) {
            echo "<option value='" . $group->group_id . "'>";
            echo $group->name;
            echo "</option>";
        }
        ?>

					</select>				
				</div>
				<div>
					<label>
						Course:
					</label>
					
					<?php 
        $course = new WP_Query(array('post_type' => 'course'));
        ?>

					
					<select name="course">
						<?php 
        // The Loop
        if ($course->have_posts()) {
            while ($course->have_posts()) {
                $course->the_post();
                echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>';
            }
        }
        /* Restore original Post Data */
        ?>
																
					</select>
					<?php 
        wp_reset_postdata();
        ?>

				</div>
				<div>				
					<label>
						How many modules should be completed by now?
					</label>	
					<input type="text" name="completionpermonth" />
				</div><br /><br />			
				<input type="submit" class="button button-primary" name="submittreshold" value="submit" />										
			</form>
		</div>	
		
		
<?php 
    } elseif ($tab == "incremental-progress") {
        wp_enqueue_script('jquery-ui-datepicker');
        wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
        //declare the wpdb for custom query
        global $wpdb;
        //check for submitted data
        if (isset($_POST['submitincrenmental']) && ($_POST['submitincrenmental'] = "submit")) {
            // declare users and variables
            $allUsers = get_users();
            $modules_completed = $_POST['completionpermonth'];
            $courseid = $_POST['course'];
            $course_name = get_the_title($courseid);
            $array_to_csv = array(array('Student Name', 'Course Name ', 'Lesson Title'));
            //user loop ----- loop user get the groups and course the course they take
            foreach ($allUsers as $user) {
                //declare course function calls
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->ID);
                $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->ID);
                $course_status_info = get_comment_meta($user_course_status->comment_ID);
                $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->ID);
                $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->ID);
                $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status);
                //get the user groups
                $useringroup = new Groups_User($user->ID);
                $user_groups = $useringroup->__get('groups');
                $displayed_lessons = array();
                //declare and get module values
                $modules = Sensei()->modules->get_course_modules(intval($courseid));
                $modules_content = Sensei()->modules->course_module_content(intval($courseid));
                $course_status_info['start'][0];
                $datenow = date('Y-m-d h:i:s');
                $date1 = date_create($course_status_info['start'][0]);
                $date2 = date_create($datenow);
                $diff = date_diff($date1, $date2);
                $diftime = $diff->format("%m");
                if ($diftime < 1) {
                    $diftime = 1;
                }
                //echo "</pre>";
                //module loop per user
                foreach ($modules as $module) {
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($courseid), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0);
                    $lessons = get_posts($args);
                    $num_of_lesson = count($lessons);
                    //lessson loop per user
                    foreach ($lessons as $lesson_item) {
                        $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $user->ID);
                        $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID);
                        $modulequizdata = get_comment_meta($lesson_status->comment_ID);
                        if (!empty($lesson_status->comment_date)) {
                            echo "<pre>";
                            //echo $lesson_status->comment_date."<br />";
                            //echo $_POST['date1']."<br />";
                            $lesson_completion_date = date("Y-m-d", strtotime($lesson_status->comment_date));
                            //echo "<br />";
                            //echo $_POST['date2']."<br />";
                            //echo "lesson is completed:".$is_lesson_completed."<br />";
                            //print_r($lesson_item);
                            echo "</pre>";
                        }
                        if ($is_lesson_completed == 1) {
                            $date1 = strtotime($_POST['date1']);
                            $date2 = strtotime($_POST['date2']);
                            $lesson_completion_date_str = strtotime($lesson_completion_date);
                            if ($lesson_completion_date_str > $date1 && $lesson_completion_date_str < $date2) {
                                //echo "lesson is completed:".$is_lesson_completed."<br />";
                                //echo "user ".$user->display_name." pass this". $lesson_completion_date;
                                $user_id_onrange[$user->ID] = $lesson_item->post_title;
                            }
                        }
                    }
                    //echo "lesson completed:". count($lesson_completed)."<br />";
                }
                //loop throughout the user group under a user
                if (is_array($user_groups)) {
                    foreach ($user_groups as $user_group) {
                        if ($user_group->group_id == $_POST['group']) {
                            if (!empty($user_course_status)) {
                                if (array_key_exists($user->ID, $user_id_onrange)) {
                                    $array_to_csv[] = array($user->display_name, $course_name, $user_id_onrange[$user->ID]);
                                }
                            }
                        }
                        //echo $user_group->group_id."<br />";
                    }
                }
            }
            //print_r($user_id_onrange);
            //echo "<pre>";
            //echo $modules_completed;
            //print_r($array_to_csv);
            //echo "</pre>";
            convert_to_csv($array_to_csv, 'report-incremental-progress' . md5(date('Y-m-d h:i:s')) . '.csv', $headers);
        }
        ?>
		<div class="form-wrap" style="padding:20px;">
			<form action="" method="post">
				
				<div>
					<label>
						Group:
					</label>
						<?php 
        $groups = $wpdb->get_results('SELECT * FROM `wp_groups_group`');
        ?>
					
					<select name="group">
						<?php 
        foreach ($groups as $group) {
            echo "<option value='" . $group->group_id . "'>";
            echo $group->name;
            echo "</option>";
        }
        ?>

					</select>				
				</div><br />
				<div>
					<label>
						Course:
					</label>
					
					<?php 
        $course = new WP_Query(array('post_type' => 'course'));
        ?>

					
					<select name="course">
						<?php 
        // The Loop
        if ($course->have_posts()) {
            while ($course->have_posts()) {
                $course->the_post();
                echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>';
            }
        }
        /* Restore original Post Data */
        ?>
																
					</select>
					<?php 
        wp_reset_postdata();
        ?>

				</div><br />
				<div>				
					<label>
						Date:
					</label>	
					From<input type="text" id="date1" name="date1" /> to <input type="text" id="date2" name="date2" />
				</div><br /><br />			
				<input type="submit" class="button button-primary" name="submitincrenmental" value="submit" />										
			</form>
		</div>	
		<script>
			jQuery(document).ready(function() {
				jQuery('#date1').datepicker({
					dateFormat : 'yy-mm-dd'
				});
				jQuery('#date2').datepicker({
					dateFormat : 'yy-mm-dd'
				});				
				
				
			});
		</script>
		
<?php 
    } elseif ($tab == "total-progress") {
        //declare the wpdb for custom query
        global $wpdb;
        //check for submitted data
        if (isset($_POST['submittotalprogress']) && ($_POST['submittotalprogress'] = "submit")) {
            // declare users and variables
            $allUsers = get_users();
            $modules_completed = $_POST['completionpermonth'];
            $courseid = $_POST['course'];
            $course_name = get_the_title($courseid);
            $array_to_csv = array(array('Student Name', 'Course Name', 'Lesson Title'));
            //user loop ----- loop user get the groups and course the course they take
            foreach ($allUsers as $user) {
                //declare course function calls
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->ID);
                $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->ID);
                $course_status_info = get_comment_meta($user_course_status->comment_ID);
                $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->ID);
                $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->ID);
                $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status);
                //get the user groups
                $useringroup = new Groups_User($user->ID);
                $user_groups = $useringroup->__get('groups');
                $displayed_lessons = array();
                //declare and get module values
                $modules = Sensei()->modules->get_course_modules(intval($courseid));
                $modules_content = Sensei()->modules->course_module_content(intval($courseid));
                //echo "<pre>";
                //echo $user->user_email."<br />";
                //echo "sensei_user_course_status_message: ";
                //print_r($course_status);
                //echo "<br />";
                //echo "started_course: "."<br />";
                $course_status_info['start'][0];
                $datenow = date('Y-m-d h:i:s');
                $date1 = date_create($course_status_info['start'][0]);
                $date2 = date_create($datenow);
                $diff = date_diff($date1, $date2);
                $diftime = $diff->format("%m");
                if ($diftime < 1) {
                    $diftime = 1;
                }
                //echo "</pre>";
                //module loop per user
                foreach ($modules as $module) {
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($courseid), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0);
                    $lessons = get_posts($args);
                    $num_of_lesson = count($lessons);
                    //lessson loop per user
                    foreach ($lessons as $lesson_item) {
                        $is_lesson_completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_item->ID, $user->ID);
                        if ($is_lesson_completed == 1) {
                            $lesson_taken[$user->ID][] = $lesson_item->post_title;
                        }
                    }
                }
                $overaalltotal_module_passed = count($total_module_passed);
                //echo $overaalltotal_module_passed . " module being passed";
                //loop throughout the user group under a user
                if (is_array($user_groups)) {
                    foreach ($user_groups as $user_group) {
                        if ($user_group->group_id == $_POST['group']) {
                            if (!empty($user_course_status)) {
                                $array_to_csv[] = array($user->display_name, $course_name, join("|", $lesson_taken[$user->ID]));
                                //$userid_within_group[$user->user_email] = $user->ID;
                            }
                        }
                        //echo $user_group->group_id."<br />";
                    }
                }
                //echo "<pre>";
                //print_r($lesson_taken);
                //echo "<pre>";
                unset($total_module_passed);
                unset($lesson_taken);
            }
            //echo "<pre>";
            //echo $modules_completed;
            //print_r($array_to_csv);
            //echo "</pre>";
            convert_to_csv($array_to_csv, 'report-total-progress' . md5(date('Y-m-d h:i:s')) . '.csv', ',');
        }
        ?>
		<div class="form-wrap" style="padding:20px;">
			<form action="" method="post">
				
				<div>
					<label>
						Group:
					</label>
						<?php 
        $groups = $wpdb->get_results('SELECT * FROM `wp_groups_group`');
        ?>
					
					<select name="group">
						<?php 
        foreach ($groups as $group) {
            echo "<option value='" . $group->group_id . "'>";
            echo $group->name;
            echo "</option>";
        }
        ?>

					</select>				
				</div>
				<div>
					<label>
						Course:
					</label>
					
					<?php 
        $course = new WP_Query(array('post_type' => 'course'));
        ?>

					
					<select name="course">
						<?php 
        // The Loop
        if ($course->have_posts()) {
            while ($course->have_posts()) {
                $course->the_post();
                echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>';
            }
        }
        /* Restore original Post Data */
        ?>
																
					</select>
					<?php 
        wp_reset_postdata();
        ?>

				</div>
				<br /><br />			
				<input type="submit" class="button button-primary" name="submittotalprogress" value="submit" />										
			</form>
		</div>	
		
		
<?php 
    }
    echo '</div>';
}
예제 #5
0
<?php

$json = $_POST['postname'];
$data = json_decode($json, true);
function convert_to_csv($input_array, $output_file_name, $delimiter)
{
    // open raw memory as file
    $f = fopen('php://output', 'w');
    foreach ($input_array as $line) {
        fputcsv($f, $line, $delimiter);
    }
    // rewrind the "file" with the csv lines
    fseek($f, 0);
    // modify header to be downloadable csv file
    header('Content-Type: application/csv');
    header('Content-Disposition: attachement; filename="' . $output_file_name . '";');
    fpassthru($f);
}
convert_to_csv($data, 'report.csv', ', ');
예제 #6
0
function savedquest_options()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    echo '<div class="wrap" style="background:#fff;">';
    if (isset($_GET['tab'])) {
        $tab = $_GET['tab'];
    } else {
        $tab = "";
    }
    saved_admin_tab($tab);
    if ($tab == "quiztaken" or $tab == "") {
        ?>

		<table  class="wp-list-table widefat fixed striped pages" width="100%" style="border-spacing: 0; text-align:center;" >

			<tr>

				<th>Lesson ID</th>

				<th>Lesson Title</th>

				<th>Module</th>

				<th>Number Of Questions</th>

				<th>Question Answered</th>

				<th>Unanswered Question</th>

				<th>User</th>

				<th>User Id</th>

				<th>DATE And Time</th>

			</tr>

			<?php 
        $svequiz = get_option('savequiz_list');
        ?>

			<?php 
        foreach ($svequiz as $quizdata) {
            ?>

			<tr>

				<td><?php 
            echo $quizdata['lesson_id'];
            ?>
</td>

				<td><?php 
            echo $quizdata['lesson_title'];
            ?>
</td>

				<td>

				<?php 
            $terms = get_the_terms($quizdata['lesson_id'], 'module');
            echo $terms[0]->name;
            //print_r($terms);
            ?>

				</td>

				<td><?php 
            echo $quizdata['total_questtion'];
            ?>
</td>

				<td><?php 
            echo $quizdata['question_answered'];
            ?>
(<?php 
            echo get_percentage($quizdata['total_questtion'], $quizdata['question_answered']) . "%";
            ?>
)</td>

				<td><?php 
            echo $quizdata['remaining_question'];
            ?>
(<?php 
            echo 100 - get_percentage($quizdata['total_questtion'], $quizdata['question_answered']) . "%";
            ?>
)</td>

				<td><?php 
            echo $quizdata['fullname'];
            ?>
</td>

				<td><?php 
            echo $quizdata['user_id'];
            ?>
 </td>

				<td><?php 
            echo $quizdata['DATETIME'];
            ?>
</td>

			</tr>

			<?php 
        }
        ?>

		</table>



	<?php 
    } elseif ($tab == "timesession") {
        $user_last_login_logout = get_option('user_last_login_logout');
        ?>

	<br /><br/>

		<table  class="wp-list-table widefat fixed striped pages" width="100%" style="border-spacing: 0; text-align:center;" >

			<tr>

				<th>User ID</th>

				<th>Full Name</th>

				<th>Last Login</th>

				<th>Last Logout</th>

				<th>Amout of Time Spent</th>

				<th>Role</th>



			</tr>

			<?php 
        $svequiz = get_option('savequiz_list');
        ?>

			<?php 
        foreach ($user_last_login_logout as $last_login_logout) {
            ?>

			<?php 
            if ($last_login_logout['user_id'] != "") {
                ?>

			<?php 
                $user_info = get_userdata($last_login_logout['user_id']);
                ?>

			<tr>

				<td><?php 
                echo $last_login_logout['user_id'];
                ?>
</td>

				<td><?php 
                echo $user_info->display_name;
                ?>
</td>

				<td><?php 
                echo gettime_st($last_login_logout['logintime']);
                ?>
</td>

				<td><?php 
                echo gettime_st($last_login_logout['logouttime']);
                ?>
</td>

				<?php 
                if ($last_login_logout['logouttime'] != "") {
                    $date1 = date_create($last_login_logout['logintime']);
                    $date2 = date_create($last_login_logout['logouttime']);
                    $diff = date_diff($date1, $date2);
                    $diftime = $diff->format("%h Hours %i Minute %s Seconds");
                } else {
                    $diftime = "";
                }
                ?>



				<th><?php 
                echo $diftime;
                ?>
</th>

				<td><?php 
                echo implode(', ', $user_info->roles);
                ?>
</td>



			</tr>

			<?php 
            }
            ?>

			<?php 
        }
        ?>

		</table><br /><br />





	<?php 
    } elseif ($tab == "timequizecompleted") {
        global $woothemes_sensei, $post, $current_user, $wp_query, $learner_user;
        echo "<table class='wp-list-table widefat fixed striped pages'>";
        $allUsers = get_users();
        echo "<tr>\n\n\t\t\t\t<th>User</th>\n\n\t\t\t\t<th>Courses</th>\n\n\t\t\t\t<th>Percentage Incomplete</th>\n\n\t\t\t\t<th>Percentage Complete</th>\n\n\t\t\t\t<th>Percentage Competent</th>\n\n\t\t\t\t<th>Percentage Attempted</th>\n\n\t\t\t\t<th>Length of time Course Completed</th>\n\n\t\t\t  </tr>";
        foreach ($allUsers as $user) {
            $args = array('post_type' => 'course');
            $courses = get_posts($args);
            $i = 1;
            foreach ($courses as $course) {
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($course->ID, $user->ID);
                $course_status = WooThemes_Sensei_Utils::user_course_status($course->ID, $user->ID);
                $course_status_update = get_comment_meta($course_status->comment_ID);
                if (!empty($course_status)) {
                    $displayed_lessons = array();
                    $modules = Sensei()->modules->get_course_modules(intval($course->ID));
                    foreach ($modules as $module) {
                        $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . $module->term_id, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'suppress_filters' => 0);
                        $lessons = get_posts($args);
                        if (count($lessons) > 0) {
                            $html .= '<h3>' . $module->name . '</h3>' . "\n";
                            $count = 0;
                            foreach ($lessons as $lesson_item) {
                                $lesson_grade = ' n/a';
                                $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true);
                                if ($has_questions) {
                                    $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID);
                                    // Get user quiz grade
                                    $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
                                    if ($lesson_grade) {
                                        $lesson_grade .= '%';
                                    }
                                    $modulequizdata = get_comment_meta($lesson_status->comment_ID);
                                    //echo "<a href='".get_post_permalink($lesson_item->ID)."'>".$lesson_item->post_title."</a><br />";
                                    $modulequestion_asked = count(explode(",", $modulequizdata['questions_asked'][0]));
                                    $moduleanswered_quiz = count(unserialize($modulequizdata['quiz_answers'][0]));
                                    //echo "number of questions:".$modulequestion_asked."<br />";
                                    //echo "number of Answered:".$moduleanswered_quiz."<br />";
                                    //echo "<pre>";
                                    //echo "<h1>".$user->user_email.$lesson_item->post_title."</h1>";
                                    //print_r($course_status );
                                    //echo $course_status->comment_approved;
                                    //echo $modulequestion_asked."------".$moduleanswered_quiz;
                                    //echo "</pre>";
                                    if ($course_status->comment_approved == "complete") {
                                        $attempted = '<span style="color:green;">(100%)</span>';
                                    } else {
                                        if ($lesson_status->comment_approved == "passed" || $lesson_status->comment_approved == "graded") {
                                            $attempted = '<span style="color:green;">(100%)</span>';
                                        } else {
                                            $attempted = "";
                                        }
                                    }
                                    //echo "<pre>";
                                    //echo "Attempted:".$attempted."<br />";
                                    //echo $user->user_email."<br />";
                                    //echo $modulequizdata['grade'][0]."<br />";
                                    //echo $modulequizdata['quiz_answers'][0]."<br />";
                                    //print_r($lesson_status);
                                    //echo "</pre>";
                                }
                                $html .= '<a href="' . esc_url(get_permalink($lesson_item->ID)) . '" title="' . esc_attr(sprintf(__('Start %s', 'woothemes-sensei'), $lesson_item->post_title)) . '">' . esc_html(sprintf(__('%s', 'woothemes-sensei'), $lesson_item->post_title)) . '</a> ' . $attempted . '<br />';
                                $displayed_lessons[] = $lesson_item->ID;
                            }
                        }
                    }
                    $args = array('post_type' => 'lesson', 'posts_per_page' => -1, 'suppress_filters' => 0, 'meta_key' => '_order_' . $course->ID, 'orderby' => 'meta_value_num date', 'order' => 'ASC', 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($course->ID))), 'post__not_in' => $displayed_lessons);
                    $lessons = get_posts($args);
                    //echo "Number of lesson in a course: ".count($lessons);
                    if (0 < count($lessons)) {
                        $html .= '<h3>' . __('Other Lessons', 'woothemes-sensei') . '</h3>' . "\n";
                    }
                    if ($course_status_update['percent'][0] == 100) {
                        $date1 = date_create($course_status_update['start'][0]);
                        $date2 = date_create($course_status->comment_date);
                        $diff = date_diff($date1, $date2);
                        $diftime = $diff->format("%h Hours %i Minute %s Seconds");
                    } else {
                        $diftime = "course not completed yet.";
                    }
                    $allcourseid[] = $course->ID;
                    $incomplete = 100 - $course_status_update['percent'][0];
                    echo "<tr><td>";
                    echo $user->user_email;
                    echo "</td>";
                    echo "<td>";
                    echo "<a href='" . get_post_permalink($course->ID) . "'>" . $course->post_title . "</a>";
                    echo "</td>";
                    echo "<td>";
                    echo $incomplete . "%";
                    echo "</td>";
                    echo "<td>";
                    echo $course_status_update['percent'][0] . "%";
                    echo "</td>";
                    echo "<td>";
                    echo $course_user_grade . "%";
                    echo "</td>";
                    echo "<td>";
                    echo $html;
                    $html = "";
                    foreach ($lessons as $lesson_item) {
                        $lesson_grade = 'n/a';
                        $has_questions = get_post_meta($lesson_item->ID, '_quiz_has_questions', true);
                        if ($has_questions) {
                            $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_item->ID, $user->ID);
                            // Get user quiz grade
                            $lesson_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
                            if ($lesson_grade) {
                                $lesson_grade .= '%';
                            }
                        }
                        $quizdata = get_comment_meta($lesson_status->comment_ID);
                        //echo "<h1>Comment</h1>";
                        //print_r(get_comment_meta( $lesson_status->comment_ID ));
                        //echo "<h1>LESSON STATUS</h1>";
                        //print_r($lesson_status);
                        echo "<a href='" . get_post_permalink($lesson_item->ID) . "'>" . $lesson_item->post_title . "</a> ";
                        //print_r($quizdata);
                        $question_asked = count(explode(",", $quizdata['questions_asked'][0]));
                        $answered_quiz = count(unserialize($quizdata['quiz_answers'][0]));
                        $lessonquestion_asked = count(explode(",", $quizdata['questions_asked'][0]));
                        $lessonanswered_quiz = count(unserialize($quizdata['quiz_answers'][0]));
                        if ($course_status->comment_approved == "complete") {
                            echo $attempted = '<span style="color:green;">(100%)</span>';
                        } else {
                            if ($lesson_status->comment_approved == "passed" || $lesson_status->comment_approved == "graded") {
                                echo $attempted = '<span style="color:green;">(100%)</span>';
                            } else {
                                echo $attempted = "";
                            }
                        }
                        /*if($quizdata ['grade'][0]==""){
                        
                        
                        
                        									if($lesson_status->comment_approved=="passed"){
                        
                        
                        
                        										 echo  $attempted = 'P/Q';
                        
                        
                        
                        									}else{
                        
                        
                        
                        										if($lessonquestion_asked>=$lessonanswered_quiz){
                        
                        
                        
                        											 if($modulequizdata['quiz_answers'][0]==""){
                        
                        
                        
                        												$attempted = "";
                        
                        
                        
                        											 }else{
                        
                        
                        
                        												 echo $attempted =  "( ". get_percentage($lessonquestion_asked, $lessonanswered_quiz)."% ) <span style='color:red;'>Saved</span>";
                        
                        
                        
                        											 }
                        
                        
                        
                        										}
                        
                        
                        
                        									}
                        
                        
                        
                        
                        
                        
                        
                        								}else{
                        
                        
                        
                        									if($lesson_status->comment_approved=="passed"){
                        
                        
                        
                        										 echo  $attempted = '100%  <span style="color:red;">complete button</span>';
                        
                        
                        
                        									}else{
                        
                        
                        
                        										$percentage = get_percentage($lessonquestion_asked, $lessonanswered_quiz);
                        
                        
                        
                        										if((int)$lessonquestion_asked>1){
                        
                        
                        
                        										}
                        
                        
                        
                        									}
                        
                        
                        
                        								}*/
                        echo '<br />';
                    }
                    // End For Loop
                    echo "</td>";
                    echo "<td>";
                    echo $diftime;
                    echo "</td>";
                    echo "</tr>";
                    //echo $course->post_title." (".$course_status_update['percent'][0]."% Complete) (". $incomplete . "% incomplete) (". $course_user_grade . "% Competent)<br />";
                    $i++;
                }
            }
        }
        echo "</table>";
    } elseif ($tab == "threshold") {
        //declare the wpdb for custom query
        global $wpdb;
        //check for submitted data
        if (isset($_POST['submittreshold']) && ($_POST['submittreshold'] = "submit")) {
            // declare users and variables
            $completionpermonth = $_POST['completionpermonth'];
            $courseid = $_POST['course'];
            $group_id = $_POST['group'];
            $course_name = get_the_title($courseid);
            $array_to_csv = array(array('Student Name', 'Course Name', 'Module(s)'));
            $userincourse = BuddyPress_Sensei_Groups::bp_sensei_get_course_members($courseid);
            //groups_get_groupmeta
            //echo $group_attached = groups_get_groupmeta( $group_id, 'bp_course_attached', true)."<br />---";
            if ($completionpermonth == "") {
                $completionpermonth = groups_get_groupmeta($group_id, 'sensei_threshold', true);
            }
            /* echo "<pre>";
            
            			print_r($userincourse);
            
            			echo "</pre>";
            
            			echo "<pre>";
            
            			print_r($user_in_groups);
            
            			echo "</pre>";	 */
            $user_in_groups = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM wp_bp_groups_members WHERE group_id = %d", $group_id));
            //user loop ----- loop user get the groups and course the course they take
            foreach ($user_in_groups as $user) {
                //echo "user_id ".$user->user_id."<br />";
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->user_id);
                $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->user_id);
                $course_status_info = get_comment_meta($user_course_status->comment_ID);
                $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->user_id);
                $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->user_id);
                $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status);
                $modules = Sensei()->modules->get_course_modules($courseid);
                //$modules_content = Sensei()->modules->course_module_content(  $courseid );
                foreach ($modules as $module) {
                    $module_id = $module->term_id;
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'module', 'field' => 'id', 'terms' => $module_id)), 'meta_query' => array(array('key' => '_lesson_course', 'value' => $courseid)), 'fields' => 'ids');
                    $lessons = get_posts($args);
                    $completed = false;
                    $lesson_count = 0;
                    $completed_count = 0;
                    foreach ($lessons as $lesson_id) {
                        $completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_id, $user->user_id);
                        ++$lesson_count;
                        if ($completed) {
                            ++$completed_count;
                        }
                    }
                    $module_progress = $completed_count / $lesson_count * 100;
                    if ($module_progress == 100) {
                        $module_passed[] = 1;
                        $module_name[] = $module->name;
                    }
                    /* 	echo "<pre>";
                    
                    						echo $module_progress;
                    
                    						echo "---<br />";
                    
                    						//print_r($modules_content);
                    
                    						echo "</pre>"; */
                }
                $course_status_info['start'][0];
                $datenow = date('Y-m-d h:i:s');
                $date1 = date_create($course_status_info['start'][0]);
                $date2 = date_create($datenow);
                $diff = date_diff($date1, $date2);
                $diftime = $diff->format("%m");
                if ($diftime < 1) {
                    $diftime = 1;
                }
                $num_of_module_x_difftime = $completionpermonth * $diftime;
                //echo "<br />num_of_module_x_difftime:".$num_of_module_x_difftime;
                //echo count($module_passed)." module passed<br />";
                if (count($module_passed) >= $num_of_module_x_difftime) {
                    $user_info = get_userdata($user->user_id);
                    $array_to_csv[] = array($user_info->display_name, $course_name, join("|", $module_name));
                    //$userid_within_group[$user->user_email] = $user->ID;
                }
                unset($module_name);
                unset($module_passed);
            }
            /* echo "<pre>";
            
            			print_r($array_to_csv);
            
            			echo "</pre>"; */
            convert_to_csv($array_to_csv, 'report-' . md5(date('Y-m-d h:i:s')) . '.csv', ',');
        }
        ?>
		<div class="form-wrap" style="padding:20px;">

			<form action="" method="post">



				<div>

					<label>

						Group:

					</label>

						<?php 
        $groups = $wpdb->get_results('SELECT * FROM `wp_bp_groups`');
        ?>

					<select name="group">

						<?php 
        foreach ($groups as $group) {
            echo "<option value='" . $group->id . "'>";
            echo $group->name;
            echo "</option>";
        }
        ?>

					</select>

				</div>

				<div>

					<label>

						Course:

					</label>



					<?php 
        $course = new WP_Query(array('post_type' => 'course'));
        ?>



					<select name="course">

						<?php 
        // The Loop
        if ($course->have_posts()) {
            while ($course->have_posts()) {
                $course->the_post();
                echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>';
            }
        }
        /* Restore original Post Data */
        ?>

					</select>

					<?php 
        wp_reset_postdata();
        ?>

				</div>

				<div>

					<label>

						How many modules should be completed by now?

					</label>

					<input type="text" name="completionpermonth" />

				</div><br /><br />

				<input type="submit" class="button button-primary" name="submittreshold" value="submit" />

			</form>

		</div>





<?php 
    } elseif ($tab == "incremental-progress") {
        wp_enqueue_script('jquery-ui-datepicker');
        wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
        //declare the wpdb for custom query
        global $wpdb;
        //check for submitted data
        if (isset($_POST['submitincrenmental']) && ($_POST['submitincrenmental'] = "submit")) {
            // declare users and variables
            $courseid = $_POST['course'];
            $group_id = $_POST['group'];
            $course_name = get_the_title($courseid);
            $array_to_csv = array(array('Student Name', 'Course Name', 'Percentage Completed', 'Percentage Competent', 'Email'));
            $userincourse = BuddyPress_Sensei_Groups::bp_sensei_get_course_members($courseid);
            $user_in_groups = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM wp_bp_groups_members WHERE group_id = %d", $group_id));
            //user loop ----- loop user get the groups and course the course they take
            foreach ($user_in_groups as $user) {
                //echo "user_id ".$user->user_id."<br />";
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->user_id);
                $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->user_id);
                $course_status_info = get_comment_meta($user_course_status->comment_ID);
                $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->user_id);
                $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->user_id);
                $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status);
                $modules = Sensei()->modules->get_course_modules($courseid);
                //$modules_content = Sensei()->modules->course_module_content(  $courseid );
                foreach ($modules as $module) {
                    $module_id = $module->term_id;
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'module', 'field' => 'id', 'terms' => $module_id)), 'meta_query' => array(array('key' => '_lesson_course', 'value' => $courseid)), 'fields' => 'ids');
                    $lessons = get_posts($args);
                    $completed = false;
                    $lesson_count = 0;
                    $completed_count = 0;
                    foreach ($lessons as $lesson_id) {
                        $completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_id, $user->user_id);
                        ++$lesson_count;
                        if ($completed) {
                            ++$completed_count;
                        }
                    }
                    $module_progress = $completed_count / $lesson_count * 100;
                    if ($module_progress == 100) {
                        $module_passed[] = 1;
                    }
                    /* 	echo "<pre>";
                    
                    						echo $module_progress;
                    
                    						echo "---<br />";
                    
                    						//print_r($modules_content);
                    
                    						echo "</pre>"; */
                }
                if ($course_status_info['percent'][0] != 0) {
                    /* echo $user_course_status->comment_date."dsaddas"."<br />"; */
                    $date1 = strtotime($_POST['date1']);
                    $date2 = strtotime($_POST['date2']);
                    $lesson_completion_date_str = strtotime($user_course_status->comment_date);
                    if ($lesson_completion_date_str > $date1 && $lesson_completion_date_str < $date2) {
                        //echo "lesson is completed:".$is_lesson_completed."<br />";
                        //echo "user ".$user->display_name." pass this". $lesson_completion_date;
                        $user_info = get_userdata($user->user_id);
                        $array_to_csv[] = array($user_info->display_name, $course_name, $course_status_info['percent'][0] . '%', $course_user_grade . '%', $user_info->user_email);
                        //$user_id_onrange[$user->ID] = $lesson_item->post_title;
                    }
                }
                unset($module_passed);
            }
            /* echo "<pre>";
            
            						print_r($array_to_csv);
            
            						echo "</pre>";  */
            $daterange1 = $_POST['date1'];
            $daterange2 = $_POST['date2'];
            convert_to_csv($array_to_csv, 'report-inc-progress_' . $daterange1 . '_' . $daterange2 . '_group_' . $groupname . '_courseID_' . $courseid . '.csv', $headers);
        }
        ?>
		<div class="form-wrap" style="padding:20px;">

			<form action="" method="post" id="incrementalval">



				<div>

					<label>

						Group:

					</label>

						<?php 
        $groups = $wpdb->get_results('SELECT * FROM `wp_bp_groups`');
        ?>

					<select name="group">

						<?php 
        foreach ($groups as $group) {
            echo "<option value='" . $group->id . "'>";
            echo $group->name;
            echo "</option>";
        }
        ?>

					</select>

				</div><br />

				<div>

					<label>

						Course:

					</label>



					<?php 
        $course = new WP_Query(array('post_type' => 'course'));
        ?>



					<select name="course">

						<?php 
        // The Loop
        if ($course->have_posts()) {
            while ($course->have_posts()) {
                $course->the_post();
                echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>';
            }
        }
        /* Restore original Post Data */
        ?>

					</select>

					<?php 
        wp_reset_postdata();
        ?>

				</div><br />

				<div>

					<label>

						Date:

					</label>

					From<input type="text" id="date1" name="date1" required /> to <input type="text" id="date2" name="date2" required />

				</div><br /><br />

				<input type="submit" class="button button-primary" name="submitincrenmental" value="submit"  />

			</form>

		</div>

		<script>

			jQuery(document).ready(function() {

				jQuery('#date1').datepicker({

					dateFormat : 'yy-mm-dd'

				});

				jQuery('#date2').datepicker({

					dateFormat : 'yy-mm-dd'

				});









			});

		</script>



<?php 
    } elseif ($tab == "total-progress") {
        //declare the wpdb for custom query
        global $wpdb;
        //check for submitted data
        if (isset($_POST['submittotalprogress']) && ($_POST['submittotalprogress'] = "submit")) {
            // declare users and variables
            $courseid = $_POST['course'];
            $group_id = $_POST['group'];
            $course_name = get_the_title($courseid);
            $array_to_csv = array(array('Student Name', 'Course Name', 'Percentage Completed', 'Percentage Competent', 'Email'));
            $userincourse = BuddyPress_Sensei_Groups::bp_sensei_get_course_members($courseid);
            $user_in_groups = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM wp_bp_groups_members WHERE group_id = %d", $group_id));
            //user loop ----- loop user get the groups and course the course they take
            foreach ($user_in_groups as $user) {
                //echo "user_id ".$user->user_id."<br />";
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->user_id);
                $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->user_id);
                $course_status_info = get_comment_meta($user_course_status->comment_ID);
                $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->user_id);
                $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->user_id);
                $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status);
                $modules = Sensei()->modules->get_course_modules($courseid);
                //$modules_content = Sensei()->modules->course_module_content(  $courseid );
                foreach ($modules as $module) {
                    $module_id = $module->term_id;
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'module', 'field' => 'id', 'terms' => $module_id)), 'meta_query' => array(array('key' => '_lesson_course', 'value' => $courseid)), 'fields' => 'ids');
                    $lessons = get_posts($args);
                    $completed = false;
                    $lesson_count = 0;
                    $completed_count = 0;
                    foreach ($lessons as $lesson_id) {
                        $completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_id, $user->user_id);
                        ++$lesson_count;
                        if ($completed) {
                            ++$completed_count;
                        }
                    }
                    $module_progress = $completed_count / $lesson_count * 100;
                    if ($module_progress == 100) {
                        $module_passed[] = 1;
                    }
                }
                $user_info = get_userdata($user->user_id);
                if ($user->user_id != 1) {
                    $percentcomplete = $course_status_info['percent'][0];
                    if ($percentcomplete == "") {
                        $percentcomplete = '0';
                    }
                    $array_to_csv[] = array($user_info->display_name, $course_name, $percentcomplete . '%', $course_user_grade . '%', $user_info->user_email);
                }
            }
            convert_to_csv($array_to_csv, 'report-total-progress_' . date('Y-m-d') . '_group_' . $groupname . '_courseID_' . $courseid . '.csv', ',');
        }
        ?>
		<div class="form-wrap" style="padding:20px;">

			<form action="" method="post">



				<div>

					<label>

						Group:

					</label>

						<?php 
        $groups = $wpdb->get_results('SELECT * FROM `wp_bp_groups`');
        ?>

					<select name="group">

						<?php 
        foreach ($groups as $group) {
            echo "<option value='" . $group->id . "'>";
            echo $group->name;
            echo "</option>";
        }
        ?>

					</select>

				</div>

				<div>

					<label>

						Course:

					</label>



					<?php 
        $course = new WP_Query(array('post_type' => 'course'));
        ?>



					<select name="course">

						<?php 
        // The Loop
        if ($course->have_posts()) {
            while ($course->have_posts()) {
                $course->the_post();
                echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>';
            }
        }
        /* Restore original Post Data */
        ?>

					</select>

					<?php 
        wp_reset_postdata();
        ?>

				</div>

				<br /><br />

				<input type="submit" class="button button-primary" name="submittotalprogress" value="submit" />

			</form>

		</div>





<?php 
    } elseif ($tab == "master-report") {
        //declare the wpdb for custom query
        global $wpdb;
        global $woothemes_sensei, $post, $current_user, $wp_query, $learner_user;
        //check for submitted data
        if (isset($_POST['master-report']) && ($_POST['master-report'] = "submit")) {
            // declare users and variables
            $courseid = $_POST['course'];
            $group_id = $_POST['group'];
            $course_name = get_the_title($courseid);
            $array_to_csv = array(array('Student Name', 'Course Name', 'Percentage Completed', 'Percentage Competent', 'Email'));
            $userincourse = BuddyPress_Sensei_Groups::bp_sensei_get_course_members($courseid);
            $user_in_groups = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM wp_bp_groups_members WHERE group_id = %d", $group_id));
            //user loop ----- loop user get the groups and course the course they take
            $maincontent = "";
            $countloop_user = 0;
            $lesson_title = "<th align='center'>User</th>";
            foreach ($user_in_groups as $user) {
                $maincontent .= "<tr>";
                $user_info = get_userdata($user->user_id);
                $maincontent .= "<td>" . $user_info->display_name . "</td>";
                $course_user_grade = WooThemes_Sensei_Utils::sensei_course_user_grade($courseid, $user->user_id);
                $user_course_status = WooThemes_Sensei_Utils::user_course_status($courseid, $user->user_id);
                $course_status_info = get_comment_meta($user_course_status->comment_ID);
                $started_course = WooThemes_Sensei_Utils::user_started_course($courseid, $user->user_id);
                $course_status = WooThemes_Sensei_Utils::sensei_user_course_status_message($courseid, $user->user_id);
                $completed_course = WooThemes_Sensei_Utils::user_completed_course($user_course_status);
                $modules = Sensei()->modules->get_course_modules($courseid);
                //$modules_content = Sensei()->modules->course_module_content(  $courseid );
                foreach ($modules as $module) {
                    $module_id = $module->term_id;
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => 'module', 'field' => 'id', 'terms' => $module_id)), 'meta_query' => array(array('key' => '_lesson_course', 'value' => $courseid)), 'fields' => 'ids', 'order' => 'ASC');
                    $lessons = get_posts($args);
                    $completed = false;
                    $lesson_count = 0;
                    $completed_count = 0;
                    foreach ($lessons as $lesson_id) {
                        if ($countloop_user != 1) {
                            $lesson_title .= "<th style=\"font-size:10px;\">";
                            $lesson_title .= get_the_title($lesson_id);
                            $lesson_title .= "</th>";
                        }
                        // Get quiz pass setting
                        $pass_required = get_post_meta($lesson_id, '_pass_required', true);
                        // Get quiz pass mark
                        $quiz_passmark = abs(round(doubleval(get_post_meta($lesson_id, '_quiz_passmark', true)), 2));
                        // Get latest quiz answers and grades
                        //$lesson_id = $woothemes_sensei->quiz->get_lesson_id( $lesson_id );
                        $user_quizzes = $woothemes_sensei->quiz->get_user_answers($lesson_id, $user->user_id);
                        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user->user_id);
                        $user_quiz_grade = 0;
                        if (isset($user_lesson_status->comment_ID)) {
                            $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
                        }
                        // Check again that the lesson is complete
                        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson($user_lesson_status);
                        $completed = WooThemes_Sensei_Utils::user_completed_lesson($lesson_id, $user->user_id);
                        /* 							echo "<pre>";
                        
                        							echo get_the_title($lesson_id);
                        
                        							echo 'pass_required:'."<br />";
                        
                        							print_r($pass_required);
                        
                        
                        
                        							echo 'quiz_passmark:<br />';
                        
                        							print_r($quiz_passmark);
                        
                        
                        
                        							echo 'user_quizzes:<br />';
                        
                        							print_r($user_quizzes);
                        
                        
                        
                        							echo 'user_lesson_status:<br />';
                        
                        							print_r($user_lesson_status);
                        
                        
                        
                        							echo 'Percent Competent:<br />';
                        
                        							print_r($user_quiz_grade);
                        
                        
                        
                        							echo 'completed--:'.$completed."<br />";
                        
                        							echo 'user_lesson_end--:'.$user_lesson_end."<br />";
                        
                        
                        
                        
                        
                        							echo "_quiz_has_questions:".get_post_meta( $lesson_id, '_quiz_has_questions', true )."<br /><br />";
                        
                        							echo "this is the lersson info-----------------:";
                        
                        							 print_r(get_comment_meta( $user_lesson_status->comment_ID ));
                        
                        							$lessonquizdata = get_comment_meta( $user_lesson_status->comment_ID );
                        
                        							echo "lessonquizdata---:";
                        
                        								print_r(unserialize($lessonquizdata['quiz_answers'][0]));
                        
                        							echo "</pre>";	 */
                        $maincontent .= "<td>";
                        if ($completed == 1) {
                            $percentcompleted = '100%';
                        } else {
                            $lessonquizdata = get_comment_meta($user_lesson_status->comment_ID);
                            $lessonquizdata_asked = count(explode(",", $lessonquizdata['questions_asked'][0]));
                            $lessonquizdataanswered_quiz = count(unserialize($lessonquizdata['quiz_answers'][0]));
                            $lquizcounter = 0;
                            foreach ($lessonquizdataanswered_quiz as $lquiz) {
                                if ($lquiz != "") {
                                    $lquizcounter++;
                                }
                            }
                            /* echo "<pre>";
                            
                            								echo $lessonquizdata_asked."<br />";
                            
                            								print_r($lessonquizdata);
                            
                            								print_r(unserialize($lessonquizdata['quiz_answers'][0]));
                            
                            								echo "</pre>"; */
                            if ($user_lesson_status->comment_approved == "passed" || $user_lesson_status->comment_approved == "graded") {
                                $percentcompleted = '100%';
                            } else {
                                $percentcompleted = get_percentage($lessonquizdata_asked, $lquizcounter) . '%';
                            }
                        }
                        $maincontent .= '%S: ' . $percentcompleted . "<br />";
                        $maincontent .= '%C: ' . $user_quiz_grade . "%";
                        $maincontent .= "</td>";
                        ++$lesson_count;
                        if ($completed) {
                            ++$completed_count;
                        }
                    }
                    $module_progress = $completed_count / $lesson_count * 100;
                    if ($module_progress == 100) {
                        $module_passed[] = 1;
                    }
                }
                $countloop_user = 1;
                $user_info = get_userdata($user->user_id);
                $completionpermonth = groups_get_groupmeta($group_id, 'sensei_threshold', true);
                if (count($module_passed) >= $completionpermonth) {
                    $ontract = "yes";
                } else {
                    $ontract = "no";
                }
                $maincontent .= "<td>" . $ontract . "</td>";
                if ($completed_course == 1) {
                    $completed_course = $user_course_status->comment_date;
                } else {
                    $completed_course = "No";
                }
                $maincontent .= "<td>" . $completed_course . "</td>";
                $maincontent .= "</tr>";
                unset($module_passed);
            }
            echo '<table  class="wp-list-table widefat fixed striped pages" style="width:500%; border-spacing: 0; text-align:center;" >';
            echo "<tr>";
            echo $lesson_title;
            echo "<td>On Track Or Not</td>";
            echo "<td>Course Completed</td>";
            echo "</tr>";
            echo $maincontent;
            echo "</table>";
            /* echo "<pre>";
            
            						print_r($array_to_csv);
            
            						echo "</pre>"; */
            //convert_to_csv($array_to_csv, 'report-total-progress_'.date('Y-m-d').'_group_'.$groupname.'_courseID_'.$courseid.'.csv', ',');
        }
        ?>
		<div class="form-wrap" style="padding:20px;">

			<form action="" method="post">



				<div>

					<label>

						Group:

					</label>

						<?php 
        $groups = $wpdb->get_results('SELECT * FROM `wp_bp_groups`');
        ?>

					<select name="group" required>

						<option value="">- Select One -</option>

						<?php 
        foreach ($groups as $group) {
            echo "<option value='" . $group->id . "'>";
            echo $group->name;
            echo "</option>";
        }
        ?>

					</select>

				</div>

				<div>

					<label>

						Course:

					</label>



					<?php 
        $course = new WP_Query(array('post_type' => 'course'));
        ?>



					<select name="course" required>

						<option value="">- Select One -</option>

						<?php 
        // The Loop
        if ($course->have_posts()) {
            while ($course->have_posts()) {
                $course->the_post();
                echo '<option value="' . $course->post->ID . '">' . get_the_title() . '</option>';
            }
        }
        /* Restore original Post Data */
        ?>

					</select>

					<?php 
        wp_reset_postdata();
        ?>

				</div>

				<br /><br />

				<input type="submit" class="button button-primary" name="master-report" value="submit" />

			</form>

		</div>





<?php 
    }
    //end master-report
    echo '</div>';
}
예제 #7
0
    // print "Date/Time = ".gmdate('m-d-Y H:i:s', $insta_date-$offset);
    $dte = $d . " (" . date("g:i a", strtotime("{$t12}")) . ")";
    return $dte;
}
function scrape_flora($plant)
{
    $id = $plant->getId();
    $date = create_date($plant->getCreated());
    $name = $plant->getName();
    $location = $plant->getLocation();
    $longitude = $plant->getLongitude();
    $latitude = $plant->getLatitude();
    $user_id = $plant->getUserId();
    //$weather_id= $plant->getWeatherId();
    $weather = $plant->getWeather();
    //$soil_id= $plant->getSoilId();
    $soil = $plant->getSoil();
    $temperature = $plant->getTemperature();
    $wind = $plant->getWind();
    $humidity = $plant->getHumidity();
    $notes = $plant->getNotes();
    return array($id, $date, $name, $location, $longitude, $latitude, $user_id, $weather, $soil, $temperature, $wind, $humidity, $notes);
}
$ret = array(array('Id', 'Date', 'Name', 'Location', 'Longitude', 'Latitude', 'User Id', 'Weather', 'Soil', 'Temperature (F)', 'Wind (mph)', 'Humidity (%)', 'Notes'));
foreach ($plants as $plant) {
    $ret[] = scrape_flora($plant);
    //var_dump(scrape_flora($plant));
}
$array_to_csv = $ret;
convert_to_csv($array_to_csv, 'flora_report.csv', ',');
    $infoArray = json_decode(request($infoUrl), true);
    // Set image @id and w/h
    $img["@id"] = $infoArray["@id"];
    $img["width"] = $infoArray["width"];
    $img["height"] = $infoArray["height"];
    array_push($csvOuputData, $img);
}
//echo "<pre>";
//print_r($csvOuputData);
//echo "</pre>";
/* ======================================
 * ## FUNCTIONS
 * ======================================
 */
// Function call to convert to csv
convert_to_csv($csvOuputData, $csvOutputFile, ',');
/* 
 * Read and retrieve CSV data
 */
function readCSV($input)
{
    $file = fopen($input, "r");
    $csv = array();
    while (($row = fgetcsv($file)) !== false) {
        $csv[] = $row;
    }
    fclose($file);
    return $csv;
}
/* 
 * Output to CSV file
예제 #9
0
foreach ($tabSemaine as $key => $value) {
    array_push($array_to_csv[2], $value["nombreHeuresMax"]);
}
array_push($array_to_csv, array('Heures Affectees (h)', ' ', ' '));
foreach ($tabSemaine as $key => $value) {
    array_push($array_to_csv[3], $value["heuresAffectees"]);
}
$i = 3;
while ($enregistrement = $select2->fetch()) {
    $i++;
    $libelle = $enregistrement->libelle;
    $nom = $enregistrement->nom;
    $partie = $enregistrement->partie;
    if ($nom == Null) {
        $nom = "#N/A";
    }
    array_push($array_to_csv, array($libelle, $nom, $partie));
    do {
        $semaine = $enregistrement->semaine;
        $nbHeures = $enregistrement->nbHeures;
        if ($nbHeures == NULL) {
            $nbHeures = 0;
        }
        array_push($array_to_csv[$i], $nbHeures);
        if ($semaine < $finsemaine) {
            $enregistrement = $select2->fetch();
        }
    } while ($semaine < $finsemaine);
}
convert_to_csv($array_to_csv, 'export.csv', ';');