הורדת רשימת תפוצה בקובץ אקסל או csv - גירסה מעודכנת

011371
הודעות: 997
הצטרף: 23:33 07/12/2017

הורדת רשימת תפוצה בקובץ אקסל או csv - גירסה מעודכנת

שליחהעל ידי 011371 » 09:07 15/04/2018

מצו"ב הקוד
עיצובים ושיפורים באדיבות "מאזין נלהב"

ניתן לבחור את סוג הקובץ שירד אקסל או csv
(גם הcsv נפתח חלק באקסל ללא תקלות)
הקובץ שנוצר יורד מיד למחשב ללא צורך בפתיחת דף נוסף

להלן הקובץ:
create.xls.csv.php.zip
(4.12 KiB) הורד 284 פעמים
וזה תוכנו

קוד: בחירת הכל

<?php



mb_internal_encoding("UTF-8");

if (isset($_REQUEST['token'])) { // אם יש טוקן

$token = $_REQUEST['token'];

} elseif (isset($_REQUEST['DID']) && isset($_REQUEST['PASS'])) { // אם אין טוקן, אבל יש שם משתמש וסיסמא

$token = token_yemot($_REQUEST['DID'], $_REQUEST['PASS']);

if(isset($token['responseStatus'])) { // אם יש שגיאה

$massage = $token['message'];
login($massage);
}

} else {

login();

}

if (!isset($_REQUEST['templateId'])) { // אם קיים הערך מספר תבנית

get_templates_form($token);
}
else {

$templateId = $_REQUEST['templateId'];
if($_REQUEST['FileType'] == 'csv' )
{ create_file_csv($token, $templateId);
}
if($_REQUEST['FileType'] == 'xls' )
{ create_file_xls($token, $templateId);
}

}

//=====================================================================================

//============= פונקציות =============================================================

//פונקציה להתחברות לימות שמחזירה את הטוקן
//הארגומנטים הנדרשים: מספר מערכת, סיסמא.
function token_yemot($DID = '' , $password = '')
{
//בדיקה האם התקבלו הארגומנטים
if ($DID == '' || $password == '') {
echo $DID;
echo $password;
echo "לא הוזן מספר מערכת או סיסמא" ;
}else{
//הכרזה על משתנה
$url_yemot="https://www.call2all.co.il/ym/api";
//הצבת הכתובת להתחברות במשתנה $url
$url= "$url_yemot/Login?username=$DID&password=$password";
//פונקציית ההתחברות, התשובה (מחרוזת json) מוחזרת למשתנה $token
$token = file_get_contents($url);
//פענוח הjson של תשובת ימות והצבתו לתוך מערך
$token = json_decode($token,TRUE);
//בדיקה האם אכן יש אישור להתחברות,
if ($token['responseStatus'] != "OK")
//אם לא
{
return $token;
//ואם כן…
}else{
//הצבת הטוקן לתוך המשתנה והחזרתו
$token = $token['token'];
return $token ;
}
}
}
//פונקצייה לקבלת כל התבניות הפונקציה מחזירה מערך של כל הרשימה
//הארגומנטים הנדרשים: טוקן
function yemot_GetTemplates($token=0)
{
//בדיקה האם התקבלו הארגומנטים
if ($token===0 )
{
echo "id_list_message=t-לא הוזן טוקן& ";
//אם התקבלו הארגומנטים ,ממשיך…
}else{
//הכרזה על משתנה
$url_yemot="https://www.call2all.co.il/ym/api";
//הצבת הכתובת להתחברות במשתנה $url
$url= "$url_yemot/GetTemplates?token=$token";
//print $url;
//פונקציית ההתחברות, התשובה (מחרוזת json) מוחזרת למשתנה $templates
$templates = file_get_contents($url);
//פענוח הjson של תשובת ימות והצבתו לתוך מערך

$templates = json_decode($templates,TRUE);

//בדיקה האם אכן יש אישור להתחברות,
if ($templates['responseStatus'] != "OK")
//אם לא
{
echo "שגיאה בקבלת רשימת התבניות מהמערכת ";

print_r($templates);
//ואם כן…
}else{
//הצבת הרשימה לתוך המשתנה והחזרתה כמערך
$templates = $templates['templates'];
return $templates ;
}
}

}

//פונקצייה לקבלת רשימת תפוצה מסוימת הפונקציה מחזירה מערך של כל הרשימה
//הארגומנטים הנדרשים: טוקן, מספר תבנית בימות.
function yemot_GetTemplateEntries($token=0,$templateId=0)
{
//בדיקה האם התקבלו הארגומנטים
if ($token===0 or $templateId<10000)
{
echo "לא הוזן מספר תבנית תקני בימות המשיח, ,שימו לב שמספר התבנית אינו המספר הסידורי שלו במערכת שלכם , אלא מספר מזהה פנימי בימות המשיח";
//אם התקבלו הארגומנטים ,ממשיך…
}else{
//הכרזה על משתנה
$url_yemot="https://www.call2all.co.il/ym/api";
//הצבת הכתובת להתחברות במשתנה $url
$url= "$url_yemot/GetTemplateEntries?token=$token&templateId=$templateId";
//פונקציית ההתחברות, התשובה (מחרוזת json) מוחזרת למשתנה $Entries
$Entries = file_get_contents($url);
//פענוח הjson של תשובת ימות והצבתו לתוך מערך

$Entries = json_decode($Entries,TRUE);
//בדיקה האם אכן יש אישור להתחברות,
if ($Entries['responseStatus'] != "OK")
//אם לא
{
echo "שגיאה בקבלת הרשימה מהמערכת , וודאו כי הזנתם מספר תבנית תקני, ,שימו לב שמספר התבנית אינו המספר הסידורי שלו במערכת שלכם , אלא מספר מזהה פנימי בימות המשיח";
//ואם כן…
}else{
//הצבת הרשימה לתוך המשתנה והחזרתה כמערך
//$Entries = $Entries['entries'];
return $Entries ;
}
}

}

// מחזירה את שורת הכותרת
function my_header() {

?>
<!DOCTYPE html>
<html>
<head>
<title>קבלת רשימת תפוצה בקובץ אקסל</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="content-language" content="he" />
<!--<link href="style.css" rel="stylesheet" />-->
<style>
@font-face {
font-family: 'Varela Round';
font-style: normal;
font-weight: 400;
src: local('Varela Round Regular'), local('VarelaRound-Regular'), url(https://fonts.gstatic.com/s/varelaround/v9/w8gdH283Tvk__Lua32TysjIfpcuPP9g.woff2) format('woff2');
unicode-range: U+0590-05FF, U+20AA, U+25CC, U+FB1D-FB4F;
}

* {
box-sizing: border-box;
}

body, html {
height: 100%;
margin: 0;
}

header {
text-align: center;
margin: 0;
background-color: #ab3b3b;
border-bottom: 4px solid #f15f5f;
color: #fff;
font-family: 'Varela Round', sans-serif;
padding: 10px;
box-shadow: 0 0 18px 5px #f15f5fbf;
position: fixed;
width: 100%;
}

a {
color: #deac8e;
}

a:hover {
color: #ead4c7;
}

a:active {
color: #f15f5f;
}

header h2 {
margin: 0;
padding: 10px;
color: wheat;
}

header p {
margin: 5px;
}


img {
top: 50px;
position: fixed;
object-fit: cover;
z-index: -1;
max-height: 100%;
min-width: 100%;
}

img.blur {
filter: blur(5px);
}

.form {
margin: auto;
width: 320px;
height: 280px;
border: 3px solid #f15f5f;
position: fixed;
text-align: center;
padding: 60px 10px;
background-color: #ffffffd1;
box-shadow: 0 0 40px 11px #f15f5fbf;
top: 0;
bottom: 0;
left: 0;
right: 0;
}

.form input {
width: 200px;
border: 1px solid #f15f5f;
border-radius: 5px;
margin: 10px;
padding: 10px;
}

.form #submit {
background-color: #ef8282;
padding: 5px;
}

.form #submit:hover {
background-color: #d85252;
}

.form #submit:active {
background-color: #a52323;
}

.form #message {
background-color: #e67e7e;
border: 2px solid #bb2121;
border-radius: 5px;
color: #7d0303;
}

.form #message p {
margin: 7px;
}

.form select {
width: 200px;
border: 1px solid #f15f5f;
border-radius: 5px;
margin: 10px;
padding: 10px;
}

footer {
font-family: 'Varela Round', sans-serif;
position: absolute;
bottom: 0;
background-color: #ab3b3b;
border-top: 4px solid #f15f5f;
width: 100%;
box-shadow: 0 0 18px 5px #f15f5fbf;
position: fixed;
}

footer p {
margin: 5px;
font-size: 12px;
color: #d48383;
padding-right: 10px;
}
</style>
</head>
<body dir="rtl">
<header>
<h2>בסייעתא דשמיא</h2>
<p>טופס להורדת קובץ אקסל של רשימת תפוצה</p>
<p>פותח על ידי "סל שרותים מתקדמים" , אימייל <a href="mailto:support@salsm.com">support@salsm.com</a></p>
</header>
<?php
}

// פונקציה שמחזירה את טופס הכניסה
// (עם הודעת שגיאה - כשצריך)
function login($message = '') {

my_header();

?>
<img class="blur" src="http://salsm.000webhostapp.com/xlsimg/img.jpg" />
<div id="login" class="form">
<?php
if($message != '') {

?><div id="message"><p><?=$message?></p></div>
<?php
}
?>

<form action="" method="POST" ENCTYPE="multipart/form-data">
<div class="row">
<input type="text" name="DID" id="user" value="" placeholder="שם משתמש"/>
</div>
<div class="row">
<input type="password" name="PASS" id="user" value="" placeholder="סיסמא"/>
</div>
<div class="row">
<input id="submit" class="button" type="submit" name="submit" value="התחבר" /><div class="clear"></div>
</div>
</form>
</div>
<?php
footer();
die();
}

// מחזירה את טופס בחירת רשימות התפוצה
function get_templates_form($token,$message = '') {

$templates = yemot_GetTemplates($token);

my_header();

?>
<img src="https://011371php.000webhostapp.com/xlsimg/img.jpg" />
<div id="login" class="form">
<?php
if($message != '') {

?><div id="message"><p><?=$message?></p></div>
<?php
}
?>

<form action="" method="POST" ENCTYPE="multipart/form-data">
<div class="row">
<input type="hidden" name="token" value="<?=$token?>" />
</div>

<div class="row">
<select id="templateId" name="templateId">
<option value="" >בחר תבנית מהרשימה</option>
<?php

foreach($templates as $template) {
?>
<option value="<?=$template['templateId']?>"><?='תבנית מספר: '. $template['templateId'].' '.$template['description']?></option>
<?php

}
?>
</select>
</div>
<div class="row">
<select id="FileType" name="FileType">
<option value="xls" >סוג הקובץ: אקסל (.xls) </option>
<option value="csv" >סוג הקובץ : csv</option>
</select>
</div>


<div class="row">
<input type="submit" id="submit" value="צור קובץ" />
</div>
<h3><a href="<?=$_SERVER['REQUEST_URI']?>">יציאה</a></h3>
</form>
</div>
<?php

footer();
die();
}

// מחזירה את הכותרת התחתונה
function footer() {

?>
<footer>
<p>עיצוב: מאזין נלהב - <a href="mailto:MaazinNilhav@gmail.com">MaazinNilhav@gmail.com</a></p>
</footer>

</body>
</html><?php


die();
}


function create_file_csv($token, $templateId) {

if ($templateId == '') {

$massage = "לא נבחרה רשימת תפוצה";
get_templates_form($token, $massage);

}

$templates = yemot_GetTemplates($token);

foreach($templates as $template) {

if ($templateId == $template['templateId']) {


$template_name = $template['description'];
break;
}
}

$Entries = yemot_GetTemplateEntries($token ,$templateId);

$template_name = str_replace(

array("?" , "|" , '"' , "%" , '&' , "'" , '*' , ',' , ':' , '<' , '>' , '/' , '\\' , '{' , '}' , '~' , " "),
"_" ,$template_name);


header('Content-Type: text/csv; charset=utf-8');

header('Content-Disposition: attachment; filename='.'תבנית_'.$templateId. "_".$template_name.".csv");

$handle = fopen( "php://output" , "w");//יצירת הקובץ

fputs($handle , $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));

fputcsv($handle, array ("מזהה רשומה" , "מספר סידורי" , "מספר טלפון" , "מצב" , "שם" , "מידע נוסף" )); //כתיבת שורת הכותרת

$Entries = $Entries['entries'];

foreach( $Entries as $Entri ) {

$Entri['blocked']==1? $Entri['blocked']='חסום' : $Entri['blocked']='פעיל' ;

fputcsv($handle, $Entri );//כתיבת הרשומה לקובץ
}


fclose($handle);//סגירת הקובץ
}


// יוצרת קובץ
function create_file_xls($token, $templateId) {

if ($templateId == '') {

$massage = "לא נבחרה רשימת תפוצה";
get_templates_form($token, $massage);

}

$templates = yemot_GetTemplates($token);

foreach($templates as $template) {

if ($templateId == $template['templateId']) {

$template_name = $template['description'];
break;
}
}

$Entries = yemot_GetTemplateEntries($token ,$templateId);

$template_name = str_replace(
array("?" , "|" , '"' , "%" , '&' , "'" , '*' , ',' , ':' , '<' , '>' , '/' , '\\' , '{' , '}' , '~' , " "),
"_" ,$template_name);

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename='.'תבנית_'.$templateId. "_".$template_name.".xls");

$handle = fopen("php://output", "w");//יצירת הקובץ

$file = '
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>קובץ רשימת תפוצה, נוצר בעזרת פיתוח של "סל שרותים מתקדמים"</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body dir="rtl">
<table border="1" >
<thead>
<tr>
<th>מזהה רשומה</th>
<th>מספר סידורי</th>
<th>מספר טלפון</th>
<th>מצב</th>
<th>שם</th>
<th>מידע נוסף</th>
</tr>
</thead>

<tbody>';

fwrite($handle, $file);

$Entries = $Entries['entries'];

foreach( $Entries as $Entri ) {

$Entri['blocked']==1? $Entri['blocked']='חסום' : $Entri['blocked']='פעיל' ;

$Entri = implode( "</td><td>" , $Entri );

fwrite($handle, '<tr><td>' . $Entri . '</td></tr>'."\r\n");
}

$file =
'
</tbody>
</table>
</body>
</html>
';

fwrite($handle, $file);//סגירת הטבלה
fclose($handle);//סגירת הקובץ

}

?>
בהצלחה
נערך לאחרונה על ידי 011371 ב 11:50 16/04/2018, נערך פעם 1 בסך הכל.


oror053
הודעות: 411
הצטרף: 14:40 01/06/2016

Re: הורדת רשימת תפוצה בקובץ אקסל או csv - גירסה מעודכנת

שליחהעל ידי oror053 » 18:31 18/07/2018

זה לא עובד ברשימות כבדות של מספרים

מנחם מענדל מענדי
הודעות: 980
הצטרף: 16:42 28/04/2016

Re: הורדת רשימת תפוצה בקובץ אקסל או csv - גירסה מעודכנת

שליחהעל ידי מנחם מענדל מענדי » 12:21 04/02/2019

011371
אני מנסה לעשות את הייצוא לאקסל לשימוש אצלי וזה פותח לי את זה באקסל אם טקסט גיבריש. ולא בעברית.
גם בסקריפט הזה ברשימות תפוצה.
אשמח לעזרה
תודה.


חזור אל “פורום מפתחים API”

מי מחובר

משתמשים הגולשים בפורום זה: אין משתמשים רשומים | 2 אורחים