محمد الحربي33 نشر 17 أبريل أرسل تقرير نشر 17 أبريل السلام عليكم بالمرفقات وكما مبين في الصوره ملف بسيط يعرض جدول تاريخ الشهر الميلادي والهجري لاكن عيبه انه يعرض الشهر الميلادي كاملا بداية من 1 الى نهاية الشهر الميلادي والمطلوب هو ان يعرض الشهر الهجري بداية من 1 الى نهاية الشهر فهل من الممكن ذلك؟ icalendar2.zip 2 اقتباس
0 Mustafa Suleiman نشر 18 أبريل أرسل تقرير نشر 18 أبريل تحتاج إلى تغيير منطق الكود بدلاً من الدوران على أيام الشهر الميلادي، إلى معرفة الشهر الهجري الحالي أو المطلوب، ثم إيجاد تاريخ 1 محرم/شوال/إلخ من ذلك الشهر الهجري بالتاريخ الميلادي. ثم إيجاد تاريخ نهاية الشهر الهجري 29 أو 30 بالتاريخ الميلادي، بعد ذلك رسم الجدول بناءً على تلك الفترة، بحيث يكون الرقم الأساسي الكبير هو التاريخ الهجري، والرقم الثانوي الصغير هو التاريخ الميلادي. ويجب نقل دالة التحويل Hijri إلى الأعلى، لاستخدامها لحساب بداية ونهاية الشهر الهجري قبل البدء برسم الجدول. <?php /* Hijri-Gregorian Calendar v.1.0. by Tayeb Habib http://redacacia.wordpress.com tayeb.habib@gmail.com a special thanks to KHALED MAMDOUH www.vbzoom.com for Hijri Conversion function Modified to display Hijri Month Grid instead of Gregorian Grid */ // Hijri conversion function // COPYRIGHT 2002 BY KHALED MAMDOUH www.vbzoom.com // Updated, and added Islamic names of months by Samir Greadly function Hijri($GetDate) { $TDays=round(strtotime($GetDate)/(60*60*24)); $HYear=round($TDays/354.37419); $Remain=$TDays-($HYear*354.37419); $HMonths=round($Remain/29.531182); $HDays=$Remain-($HMonths*29.531182); $HYear=$HYear+1389; $HMonths=$HMonths+10; $HDays=$HDays+23; if ($HDays>29.531188 and round($HDays)!=30) { $HMonths=$HMonths+1; $HDays=Round($HDays-29.531182); } else { $HDays=Round($HDays); } if($HMonths>12) { $HMonths=$HMonths-12; $HYear=$HYear+1; } return array ($HDays, $HMonths, $HYear); } //set here font, background etc for the calendar $fontfamily = isset($fontfamily) ? $fontfamily : "Verdana"; $defaultfontcolor = isset($defaultfontcolor) ? $defaultfontcolor : "#000000"; $defaultbgcolor = isset($defaultbgcolor) ? $defaultbgcolor : "#E0E0E0"; $defaultwbgcolor = isset($defaultwbgcolor) ? $defaultwbgcolor : "#F5F4D3"; $todayfontcolor = isset($todayfontcolor) ? $todayfontcolor : "#000000"; $todaybgcolor = isset($todaybgcolor) ? $todaybgcolor : "#F2BFBF"; $monthcolor = isset($monthcolor) ? $monthcolor : "#000000"; $relfontsize = isset($relfontsize) ? $relfontsize : "1"; $cssfontsize = isset($cssfontsize) ? $cssfontsize : "7pt"; // obtain month, today date etc $month = (isset($month)) ? $month : date("n",time()); $year = (isset($year)) ? $year : date("Y",time()); $todayStr = date("Y-m-d", time()); // Today's full date for accurate comparison // The Names of Hijri months $mname = array("Muharram","Safar","Rabi'ul Awal","Rabi'ul Akhir","Jamadil Awal","Jamadil Akhir","Rajab","Sha'ban","Ramadhan","Shawwal","Zul Qida","Zul Hijja"); // Determine the target Hijri Month based on the middle of the Gregorian month input $midGregorian = date("Y-m-d", mktime(1,1,1,$month,15,$year)); list($tmpHDays, $targetHMonth, $targetHYear) = Hijri($midGregorian); // Find the Gregorian date for Hijri Day 1 of the target month $searchStartDate = date("Y-m-d", mktime(1,1,1,$month,1,$year)); $hijriStartGregorian = null; for ($i = -30; $i <= 30; $i++) { $checkDate = date("Y-m-d", strtotime("$searchStartDate $i days")); list($h_d, $h_m, $h_y) = Hijri($checkDate); if ($h_y == $targetHYear && $h_m == $targetHMonth && $h_d == 1) { $hijriStartGregorian = $checkDate; break; } } if (!$hijriStartGregorian) $hijriStartGregorian = $searchStartDate; // Fallback // Find the Gregorian date for the end of the Hijri month (29 or 30) $hijriEndGregorian = null; for ($i = 0; $i <= 30; $i++) { $checkDate = date("Y-m-d", strtotime("$hijriStartGregorian $i days")); list($h_d, $h_m, $h_y) = Hijri($checkDate); if ($h_y == $targetHYear && $h_m == $targetHMonth && $h_d == 29) { $nextDate = date("Y-m-d", strtotime("$checkDate + 1 days")); list($nd, $nm, $ny) = Hijri($nextDate); if ($nm == $targetHMonth && $nd == 30) { $hijriEndGregorian = $nextDate; // It's a 30-day month } else { $hijriEndGregorian = $checkDate; // It's a 29-day month } break; } } if (!$hijriEndGregorian) $hijriEndGregorian = date("Y-m-d", strtotime("$hijriStartGregorian + 29 days")); // Calculate Grid Boundaries (Start on Sunday, End on Saturday) $startDayOfWeek = date("w", strtotime($hijriStartGregorian)); $gridStartDate = date("Y-m-d", strtotime("$hijriStartGregorian - $startDayOfWeek days")); $endDayOfWeek = date("w", strtotime($hijriEndGregorian)); $daysToAdd = 6 - $endDayOfWeek; $gridEndDate = date("Y-m-d", strtotime("$hijriEndGregorian + $daysToAdd days")); // Prepare Header Text $smon_hijri = "<font color=red>".$mname[$targetHMonth-1]." ".$targetHYear."</font>"; $startGregorianText = date("F Y", strtotime($hijriStartGregorian)); $endGregorianText = date("F Y", strtotime($hijriEndGregorian)); $smon_gregorian = $startGregorianText; if ($startGregorianText != $endGregorianText) { $smon_gregorian .= " - " . $endGregorianText; } ?> <div align="center"> <center><table border="0" cellpadding="0" cellspacing="1" width="100%" bgcolor='black'> <tr> <td valign="top" align="center"> <table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor='white' valign='top'> <tr> <td bgcolor="#C6D4E5" colspan="7" align="center"> <font color="<?php echo $monthcolor ?>" face="Verdana" size="2"> <b><?PHP echo $smon_hijri."<br />".$smon_gregorian; ?></b> </font> </td> </tr> <tr> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> M </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> W </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> F </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font></td> </tr> <? // 5. Generate Calendar Grid Day by Day $currentDate = $gridStartDate; $rowStarted = false; while (strtotime($currentDate) <= strtotime($gridEndDate)) { $dayofweek = date("w", strtotime($currentDate)); // Start new row on Sunday if ($dayofweek == 0) { echo " <tr bgcolor=\"$defaultbgcolor\">\n"; $rowStarted = true; } // Get Hijri & Gregorian data for the current cell list($h_d, $h_m, $h_y) = Hijri($currentDate); $g_d = date("j", strtotime($currentDate)); // Is this day within our target Hijri month? $isInHijriMonth = ($h_y == $targetHYear && $h_m == $targetHMonth); // Set Colors if ($currentDate == $todayStr) { $fontcolor = $todayfontcolor; $bgcellcolor = $todaybgcolor; } elseif ($isInHijriMonth) { $fontcolor = $defaultfontcolor; $bgcellcolor = $defaultbgcolor; } else { // Days outside the Hijri month (Greyed out) $fontcolor = "#CCCCCC"; $bgcellcolor = "#FFFFFF"; } $width = "14%"; if($dayofweek == 0 || $dayofweek == 6) $width = "15%"; ?> <td bgcolor="<?=$bgcellcolor ?>" valign="middle" align="center" width="<?=$width ?>"> <?PHP if ($isInHijriMonth) { // Display Hijri Day prominently (Large), and Gregorian Day smaller in red below it echo "<font color=\"$fontcolor\" face=\"$fontfamily\" size=\"2\"><b>$h_d</b></font><br/>"; echo "<font color=\"red\" face=\"$fontfamily\" size=\"1\">$g_d</font>"; } else { // Display Gregorian day faded for days outside the Hijri month echo "<font color=\"$fontcolor\" face=\"$fontfamily\" size=\"1\">$g_d</font>"; } ?> </td> <?PHP // End row on Saturday if ($dayofweek == 6) { echo " </tr>\n"; $rowStarted = false; } // Move to next day $currentDate = date("Y-m-d", strtotime("$currentDate + 1 days")); } // Close row if loop ended unexpectedly if ($rowStarted) echo " </tr>\n"; ?> </table> </td> </tr> </td></tr> </table> الأيام الميلادية التي تقع في بداية الجدول أو نهايته ولكنها لا تنتمي للشهر الهجري الحالي تظهر بلون رمادي باهت لتمييزها. 1 اقتباس
0 محمد عاطف25 نشر 18 أبريل أرسل تقرير نشر 18 أبريل وعليكم السلام ورحمة الله وبركاته . لتحقيق ما تريده فنخن نحتاج إلى عكس منطق الكود فبدلا من أن نعتمد على الشهر الميلادي كعنصر أساسي ونبحث عن ما يوافق أيامه بالتاريخ الهجري سنجعل الشهر الهجري هو الأساس. وسنقوم بالبحث عن تاريخ بداية الشهر الهجري الحالي أو المطلوب بالميلادي ثم نحسب عدد أيامه 29 أو 30 يوما ونرسم الجدول بناء على ذلك بحيث يكون الرقم الأساسي هو الهجري والرقم الفرعي باللون الأحمر هو الميلادي. وإليك الكود التالي الصحيح : <?php /* Hijri-Gregorian Calendar v.1.0. by Tayeb Habib http://redacacia.wordpress.com tayeb.habib@gmail.com a special thanks to KHALED MAMDOUH www.vbzoom.com for Hijri Conversion function */ $fontfamily = isset($fontfamily) ? $fontfamily : "Verdana"; $defaultfontcolor = isset($defaultfontcolor) ? $defaultfontcolor : "#000000"; $defaultbgcolor = isset($defaultbgcolor) ? $defaultbgcolor : "#E0E0E0"; $defaultwbgcolor = isset($defaultwbgcolor) ? $defaultwbgcolor : "#F5F4D3"; $todayfontcolor = isset($todayfontcolor) ? $todayfontcolor : "#000000"; $todaybgcolor = isset($todaybgcolor) ? $todaybgcolor : "#F2BFBF"; $monthcolor = isset($monthcolor) ? $monthcolor : "#000000"; function Hijri($GetDate) { $TDays=round(strtotime($GetDate)/(60*60*24)); $HYear=round($TDays/354.37419); $Remain=$TDays-($HYear*354.37419); $HMonths=round($Remain/29.531182); $HDays=$Remain-($HMonths*29.531182); $HYear=$HYear+1389; $HMonths=$HMonths+10; $HDays=$HDays+23; if ($HDays>29.531188 and round($HDays)!=30) { $HMonths=$HMonths+1; $HDays=Round($HDays-29.531182); } else { $HDays=Round($HDays); } if($HMonths>12) { $HMonths=$HMonths-12; $HYear=$HYear+1; } return array ($HDays, $HMonths, $HYear); } $mname = array("Muharram","Safar","Rabi'ul Awal","Rabi'ul Akhir","Jamadil Awal","Jamadil Akhir","Rajab","Sha'ban","Ramadhan","Shawwal","Zul Qida","Zul Hijja"); $monthnames = array("January","February","March","April","May","June","July","August","September","October","November","December"); $current_greg_date = date("Y-m-d"); list($today_h_d, $today_h_m, $today_h_y) = Hijri($current_greg_date); $target_h_m = (isset($h_month)) ? $h_month : $today_h_m; $target_h_y = (isset($h_year)) ? $h_year : $today_h_y; $greg_timestamp = time(); $greg_timestamp -= ($today_h_d - 1) * 86400; while (true) { list($test_d, $test_m, $test_y) = Hijri(date("Y-m-d", $greg_timestamp)); if ($test_y == $target_h_y && $test_m == $target_h_m && $test_d == 1) { break; } elseif (($test_y > $target_h_y) || ($test_y == $target_h_y && $test_m > $target_h_m) || ($test_y == $target_h_y && $test_m == $target_h_m && $test_d > 1)) { $greg_timestamp -= 86400; } else { $greg_timestamp += 86400; } } $start_greg_timestamp = $greg_timestamp; $dayone = date("w", $start_greg_timestamp); $hijri_days = 0; $curr_timestamp = $start_greg_timestamp; while (true) { list($test_d, $test_m, $test_y) = Hijri(date("Y-m-d", $curr_timestamp)); if ($test_m != $target_h_m) break; $hijri_days++; $curr_timestamp += 86400; if ($hijri_days > 30) break; } $end_greg_timestamp = $start_greg_timestamp + ($hijri_days - 1) * 86400; $daylast = date("w", $end_greg_timestamp); $start_greg_m = date("n", $start_greg_timestamp); $start_greg_y = date("Y", $start_greg_timestamp); $end_greg_m = date("n", $end_greg_timestamp); $end_greg_y = date("Y", $end_greg_timestamp); if ($start_greg_m == $end_greg_m) { $greg_span = "<font color=red>".$monthnames[$start_greg_m - 1]." ".$start_greg_y."</font>"; } else { $greg_span = "<font color=red>".$monthnames[$start_greg_m - 1]." ".$start_greg_y." - ".$monthnames[$end_greg_m - 1]." ".$end_greg_y."</font>"; } $hijri_month_name = $mname[$target_h_m - 1]; $is_current_month = ($target_h_m == $today_h_m && $target_h_y == $today_h_y); ?> <div align="center"> <center><table border="0" cellpadding="0" cellspacing="1" width="100%" bgcolor='black'> <tr> <td valign="top" align="center"> <table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor='white' valign='top'> <tr> <td bgcolor="#C6D4E5" colspan="7" align="center"> <font color="<?php echo $monthcolor ?>" face="Verdana" size="2"> <b><?PHP echo $hijri_month_name." ".$target_h_y."<br />".$greg_span ?></b> </font> </td> </tr> <tr> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> M </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> W </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> F </b></font></td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"><font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font></td> </tr> <?php $span1 = $dayone; $span2 = 6 - $daylast; for($i = 1; $i <= $hijri_days; $i++): $current_loop_timestamp = $start_greg_timestamp + ($i - 1) * 86400; $dayofweek = date("w", $current_loop_timestamp); $width = ($dayofweek == 0 || $dayofweek == 6) ? "15%" : "14%"; if($is_current_month && $i == $today_h_d): $fontcolor = $todayfontcolor; $bgcellcolor = $todaybgcolor; else: $fontcolor = $defaultfontcolor; $bgcellcolor = $defaultbgcolor; endif; $greg_day = date("j", $current_loop_timestamp); if($i == 1 || $dayofweek == 0): echo " <tr bgcolor=\"$defaultbgcolor\">\n"; if($span1 > 0 && $i == 1) echo " <td align=\"left\" bgcolor=\"#999999\" colspan=\"$span1\"><font face=\"null\" size=\"1\"> </font></td>\n"; endif; ?> <td bgcolor="<?=$bgcellcolor ?>" valign="middle" align="center" width="<?=$width ?>"> <font color="<?PHP echo $fontcolor ?>" face="<?=$fontfamily ?>" size="1"> <?PHP echo $i."<br/><font color=red>".$greg_day."</font>"; ?> </font> </td> <?PHP if($i == $hijri_days): if($span2 > 0) echo " <td align=\"left\" bgcolor=\"#999999\" colspan=\"$span2\"><font face=\"null\" size=\"1\"> </font></td>\n"; endif; if($dayofweek == 6 || $i == $hijri_days): echo " </tr>\n"; endif; endfor; ?> </table> </td> </tr> </table> </div> وإليك ما قمت بتعديله لك في الكود : الأساس الهجري: الكود أصبح الآن يبحث أولا عن التاريخ الميلادي الذي يبدأ فيه الشهر الهجري المستهدف بدلا من العكس. العنوان العلوي (Header): يعرض الآن اسم الشهر الهجري وسنته بالأسود وأسفله امتداد الأشهر الميلادية باللون الأحمر. الدوران (Loop): أصبح يمتد من 1 وحتى 29 أو 30 حسب طول الشهر الهجري الفعلي. العرض: يطبع رقم اليوم الهجري في الأعلى واليوم الميلادي الموافق له تحته باللون الأحمر. تظليل اليوم الحالي: تم تعديل منطق تحديد اليوم الحالي ليتعرف عليه داخل سياق الأيام الهجرية ويظلله باللون الوردي المعتاد بشكل صحيح. 1 اقتباس
0 محمد الحربي33 نشر 18 أبريل الكاتب أرسل تقرير نشر 18 أبريل (معدل) الله يعطيكم العافيه على التفاعل والردود الايجابيه وصلت الفكره على العموم كان ردي متأخرا بسبب انه لم يصلني بريد بوجود ردود او اقتباسات بالنسبة للكود الاول ظهر خطأ برمجي فيه ولم يعرض التاريخ بالنسبه للكود الثاني خطأ في التقويم غير موافق لتقويم ام القرى وماقصرتم حاولتم المساعده تم التعديل في 18 أبريل بواسطة محمد الحربي33 خطا بعد تجربة الكود اقتباس
0 Mustafa Suleiman نشر 19 أبريل أرسل تقرير نشر 19 أبريل بتاريخ 12 ساعة قال محمد الحربي33: الله يعطيكم العافيه على التفاعل والردود الايجابيه وصلت الفكره على العموم كان ردي متأخرا بسبب انه لم يصلني بريد بوجود ردود او اقتباسات بالنسبة للكود الاول ظهر خطأ برمجي فيه ولم يعرض التاريخ بالنسبه للكود الثاني خطأ في التقويم غير موافق لتقويم ام القرى وماقصرتم حاولتم المساعده سيظهر لك خطأ قوس { زائد في السطر 203 في حال ميزة الوسوم المختصرة معطلة في بيئة التطوير لديك وهي معطلة افتراضيًا في لاراجون short_open_tag = Off في إعدادات PHP، لذا السيرفر يتعامل مع السطر <? وما يليه على أنه مجرد كود HTML عادي ولا يقوم بتنفيذه ككود PHP. الكود التالي يستخدم الوسوم الكاملة: <?php /* Hijri-Gregorian Calendar v.1.0. by Tayeb Habib http://redacacia.wordpress.com tayeb.habib@gmail.com a special thanks to KHALED MAMDOUH www.vbzoom.com for Hijri Conversion function Modified to display Hijri Month Grid instead of Gregorian Grid */ // Hijri conversion function // COPYRIGHT 2002 BY KHALED MAMDOUH www.vbzoom.com // Updated, and added Islamic names of months by Samir Greadly function Hijri($GetDate) { $TDays = round(strtotime($GetDate) / (60 * 60 * 24)); $HYear = round($TDays / 354.37419); $Remain = $TDays - ($HYear * 354.37419); $HMonths = round($Remain / 29.531182); $HDays = $Remain - ($HMonths * 29.531182); $HYear = $HYear + 1389; $HMonths = $HMonths + 10; $HDays = $HDays + 23; if ($HDays > 29.531188 and round($HDays) != 30) { $HMonths = $HMonths + 1; $HDays = Round($HDays - 29.531182); } else { $HDays = Round($HDays); } if ($HMonths > 12) { $HMonths = $HMonths - 12; $HYear = $HYear + 1; } return array($HDays, $HMonths, $HYear); } //set here font, background etc for the calendar $fontfamily = isset($fontfamily) ? $fontfamily : "Verdana"; $defaultfontcolor = isset($defaultfontcolor) ? $defaultfontcolor : "#000000"; $defaultbgcolor = isset($defaultbgcolor) ? $defaultbgcolor : "#E0E0E0"; $defaultwbgcolor = isset($defaultwbgcolor) ? $defaultwbgcolor : "#F5F4D3"; $todayfontcolor = isset($todayfontcolor) ? $todayfontcolor : "#000000"; $todaybgcolor = isset($todaybgcolor) ? $todaybgcolor : "#F2BFBF"; $monthcolor = isset($monthcolor) ? $monthcolor : "#000000"; $relfontsize = isset($relfontsize) ? $relfontsize : "1"; $cssfontsize = isset($cssfontsize) ? $cssfontsize : "7pt"; // obtain month, today date etc $month = (isset($month)) ? $month : date("n", time()); $year = (isset($year)) ? $year : date("Y", time()); $todayStr = date("Y-m-d", time()); // Today's full date for accurate comparison // The Names of Hijri months $mname = array("Muharram", "Safar", "Rabi'ul Awal", "Rabi'ul Akhir", "Jamadil Awal", "Jamadil Akhir", "Rajab", "Sha'ban", "Ramadhan", "Shawwal", "Zul Qida", "Zul Hijja"); // Determine the target Hijri Month based on the middle of the Gregorian month input $midGregorian = date("Y-m-d", mktime(1, 1, 1, $month, 15, $year)); list($tmpHDays, $targetHMonth, $targetHYear) = Hijri($midGregorian); // Find the Gregorian date for Hijri Day 1 of the target month $searchStartDate = date("Y-m-d", mktime(1, 1, 1, $month, 1, $year)); $hijriStartGregorian = null; for ($i = -30; $i <= 30; $i++) { $checkDate = date("Y-m-d", strtotime("$searchStartDate $i days")); list($h_d, $h_m, $h_y) = Hijri($checkDate); if ($h_y == $targetHYear && $h_m == $targetHMonth && $h_d == 1) { $hijriStartGregorian = $checkDate; break; } } if (!$hijriStartGregorian) $hijriStartGregorian = $searchStartDate; // Fallback // Find the Gregorian date for the end of the Hijri month (29 or 30) $hijriEndGregorian = null; for ($i = 0; $i <= 30; $i++) { $checkDate = date("Y-m-d", strtotime("$hijriStartGregorian $i days")); list($h_d, $h_m, $h_y) = Hijri($checkDate); if ($h_y == $targetHYear && $h_m == $targetHMonth && $h_d == 29) { $nextDate = date("Y-m-d", strtotime("$checkDate + 1 days")); list($nd, $nm, $ny) = Hijri($nextDate); if ($nm == $targetHMonth && $nd == 30) { $hijriEndGregorian = $nextDate; // It's a 30-day month } else { $hijriEndGregorian = $checkDate; // It's a 29-day month } break; } } if (!$hijriEndGregorian) $hijriEndGregorian = date("Y-m-d", strtotime("$hijriStartGregorian + 29 days")); // Calculate Grid Boundaries (Start on Sunday, End on Saturday) $startDayOfWeek = date("w", strtotime($hijriStartGregorian)); $gridStartDate = date("Y-m-d", strtotime("$hijriStartGregorian - $startDayOfWeek days")); $endDayOfWeek = date("w", strtotime($hijriEndGregorian)); $daysToAdd = 6 - $endDayOfWeek; $gridEndDate = date("Y-m-d", strtotime("$hijriEndGregorian + $daysToAdd days")); // Prepare Header Text $smon_hijri = "<font color=red>" . $mname[$targetHMonth - 1] . " " . $targetHYear . "</font>"; $startGregorianText = date("F Y", strtotime($hijriStartGregorian)); $endGregorianText = date("F Y", strtotime($hijriEndGregorian)); $smon_gregorian = $startGregorianText; if ($startGregorianText != $endGregorianText) { $smon_gregorian .= " - " . $endGregorianText; } ?> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="1" width="100%" bgcolor='black'> <tr> <td valign="top" align="center"> <table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor='white' valign='top'> <tr> <td bgcolor="#C6D4E5" colspan="7" align="center"> <font color="<?php echo $monthcolor ?>" face="Verdana" size="2"> <b><?PHP echo $smon_hijri . "<br />" . $smon_gregorian; ?></b> </font> </td> </tr> <tr> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> M </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> W </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> F </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font> </td> </tr> <?php // 5. Generate Calendar Grid Day by Day $currentDate = $gridStartDate; $rowStarted = false; while (strtotime($currentDate) <= strtotime($gridEndDate)) { $dayofweek = date("w", strtotime($currentDate)); // Start new row on Sunday if ($dayofweek == 0) { echo " <tr bgcolor=\"$defaultbgcolor\">\n"; $rowStarted = true; } // Get Hijri & Gregorian data for the current cell list($h_d, $h_m, $h_y) = Hijri($currentDate); $g_d = date("j", strtotime($currentDate)); // Is this day within our target Hijri month? $isInHijriMonth = ($h_y == $targetHYear && $h_m == $targetHMonth); // Set Colors if ($currentDate == $todayStr) { $fontcolor = $todayfontcolor; $bgcellcolor = $todaybgcolor; } elseif ($isInHijriMonth) { $fontcolor = $defaultfontcolor; $bgcellcolor = $defaultbgcolor; } else { // Days outside the Hijri month (Greyed out) $fontcolor = "#CCCCCC"; $bgcellcolor = "#FFFFFF"; } $width = "14%"; if ($dayofweek == 0 || $dayofweek == 6) $width = "15%"; ?> <td bgcolor="<?= $bgcellcolor ?>" valign="middle" align="center" width="<?= $width ?>"> <?PHP if ($isInHijriMonth) { // Display Hijri Day prominently (Large), and Gregorian Day smaller in red below it echo "<font color=\"$fontcolor\" face=\"$fontfamily\" size=\"2\"><b>$h_d</b></font><br/>"; echo "<font color=\"red\" face=\"$fontfamily\" size=\"1\">$g_d</font>"; } else { // Display Gregorian day faded for days outside the Hijri month echo "<font color=\"$fontcolor\" face=\"$fontfamily\" size=\"1\">$g_d</font>"; } ?> </td> <?PHP // End row on Saturday if ($dayofweek == 6) { echo " </tr>\n"; $rowStarted = false; } // Move to next day $currentDate = date("Y-m-d", strtotime("$currentDate + 1 days")); } // Close row if loop ended unexpectedly if ($rowStarted) echo " </tr>\n"; ?> </table> </td> </tr> </table> </center> </div> 1 اقتباس
0 محمد الحربي33 نشر 19 أبريل الكاتب أرسل تقرير نشر 19 أبريل بتاريخ 1 ساعة قال Mustafa Suleiman: سيظهر لك خطأ قوس { زائد في السطر 203 في حال ميزة الوسوم المختصرة معطلة في بيئة التطوير لديك وهي معطلة افتراضيًا في لاراجون short_open_tag = Off في إعدادات PHP، لذا السيرفر يتعامل مع السطر <? وما يليه على أنه مجرد كود HTML عادي ولا يقوم بتنفيذه ككود PHP. الكود التالي يستخدم الوسوم الكاملة: <?php /* Hijri-Gregorian Calendar v.1.0. by Tayeb Habib http://redacacia.wordpress.com tayeb.habib@gmail.com a special thanks to KHALED MAMDOUH www.vbzoom.com for Hijri Conversion function Modified to display Hijri Month Grid instead of Gregorian Grid */ // Hijri conversion function // COPYRIGHT 2002 BY KHALED MAMDOUH www.vbzoom.com // Updated, and added Islamic names of months by Samir Greadly function Hijri($GetDate) { $TDays = round(strtotime($GetDate) / (60 * 60 * 24)); $HYear = round($TDays / 354.37419); $Remain = $TDays - ($HYear * 354.37419); $HMonths = round($Remain / 29.531182); $HDays = $Remain - ($HMonths * 29.531182); $HYear = $HYear + 1389; $HMonths = $HMonths + 10; $HDays = $HDays + 23; if ($HDays > 29.531188 and round($HDays) != 30) { $HMonths = $HMonths + 1; $HDays = Round($HDays - 29.531182); } else { $HDays = Round($HDays); } if ($HMonths > 12) { $HMonths = $HMonths - 12; $HYear = $HYear + 1; } return array($HDays, $HMonths, $HYear); } //set here font, background etc for the calendar $fontfamily = isset($fontfamily) ? $fontfamily : "Verdana"; $defaultfontcolor = isset($defaultfontcolor) ? $defaultfontcolor : "#000000"; $defaultbgcolor = isset($defaultbgcolor) ? $defaultbgcolor : "#E0E0E0"; $defaultwbgcolor = isset($defaultwbgcolor) ? $defaultwbgcolor : "#F5F4D3"; $todayfontcolor = isset($todayfontcolor) ? $todayfontcolor : "#000000"; $todaybgcolor = isset($todaybgcolor) ? $todaybgcolor : "#F2BFBF"; $monthcolor = isset($monthcolor) ? $monthcolor : "#000000"; $relfontsize = isset($relfontsize) ? $relfontsize : "1"; $cssfontsize = isset($cssfontsize) ? $cssfontsize : "7pt"; // obtain month, today date etc $month = (isset($month)) ? $month : date("n", time()); $year = (isset($year)) ? $year : date("Y", time()); $todayStr = date("Y-m-d", time()); // Today's full date for accurate comparison // The Names of Hijri months $mname = array("Muharram", "Safar", "Rabi'ul Awal", "Rabi'ul Akhir", "Jamadil Awal", "Jamadil Akhir", "Rajab", "Sha'ban", "Ramadhan", "Shawwal", "Zul Qida", "Zul Hijja"); // Determine the target Hijri Month based on the middle of the Gregorian month input $midGregorian = date("Y-m-d", mktime(1, 1, 1, $month, 15, $year)); list($tmpHDays, $targetHMonth, $targetHYear) = Hijri($midGregorian); // Find the Gregorian date for Hijri Day 1 of the target month $searchStartDate = date("Y-m-d", mktime(1, 1, 1, $month, 1, $year)); $hijriStartGregorian = null; for ($i = -30; $i <= 30; $i++) { $checkDate = date("Y-m-d", strtotime("$searchStartDate $i days")); list($h_d, $h_m, $h_y) = Hijri($checkDate); if ($h_y == $targetHYear && $h_m == $targetHMonth && $h_d == 1) { $hijriStartGregorian = $checkDate; break; } } if (!$hijriStartGregorian) $hijriStartGregorian = $searchStartDate; // Fallback // Find the Gregorian date for the end of the Hijri month (29 or 30) $hijriEndGregorian = null; for ($i = 0; $i <= 30; $i++) { $checkDate = date("Y-m-d", strtotime("$hijriStartGregorian $i days")); list($h_d, $h_m, $h_y) = Hijri($checkDate); if ($h_y == $targetHYear && $h_m == $targetHMonth && $h_d == 29) { $nextDate = date("Y-m-d", strtotime("$checkDate + 1 days")); list($nd, $nm, $ny) = Hijri($nextDate); if ($nm == $targetHMonth && $nd == 30) { $hijriEndGregorian = $nextDate; // It's a 30-day month } else { $hijriEndGregorian = $checkDate; // It's a 29-day month } break; } } if (!$hijriEndGregorian) $hijriEndGregorian = date("Y-m-d", strtotime("$hijriStartGregorian + 29 days")); // Calculate Grid Boundaries (Start on Sunday, End on Saturday) $startDayOfWeek = date("w", strtotime($hijriStartGregorian)); $gridStartDate = date("Y-m-d", strtotime("$hijriStartGregorian - $startDayOfWeek days")); $endDayOfWeek = date("w", strtotime($hijriEndGregorian)); $daysToAdd = 6 - $endDayOfWeek; $gridEndDate = date("Y-m-d", strtotime("$hijriEndGregorian + $daysToAdd days")); // Prepare Header Text $smon_hijri = "<font color=red>" . $mname[$targetHMonth - 1] . " " . $targetHYear . "</font>"; $startGregorianText = date("F Y", strtotime($hijriStartGregorian)); $endGregorianText = date("F Y", strtotime($hijriEndGregorian)); $smon_gregorian = $startGregorianText; if ($startGregorianText != $endGregorianText) { $smon_gregorian .= " - " . $endGregorianText; } ?> <div align="center"> <center> <table border="0" cellpadding="0" cellspacing="1" width="100%" bgcolor='black'> <tr> <td valign="top" align="center"> <table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor='white' valign='top'> <tr> <td bgcolor="#C6D4E5" colspan="7" align="center"> <font color="<?php echo $monthcolor ?>" face="Verdana" size="2"> <b><?PHP echo $smon_hijri . "<br />" . $smon_gregorian; ?></b> </font> </td> </tr> <tr> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> M </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> W </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> T </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="14%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> F </b></font> </td> <td bgcolor="<?PHP echo $defaultwbgcolor ?>" valign="middle" align="center" width="15%"> <font face="<?PHP echo $fontfamily ?>" size="1"><b> S </b></font> </td> </tr> <?php // 5. Generate Calendar Grid Day by Day $currentDate = $gridStartDate; $rowStarted = false; while (strtotime($currentDate) <= strtotime($gridEndDate)) { $dayofweek = date("w", strtotime($currentDate)); // Start new row on Sunday if ($dayofweek == 0) { echo " <tr bgcolor=\"$defaultbgcolor\">\n"; $rowStarted = true; } // Get Hijri & Gregorian data for the current cell list($h_d, $h_m, $h_y) = Hijri($currentDate); $g_d = date("j", strtotime($currentDate)); // Is this day within our target Hijri month? $isInHijriMonth = ($h_y == $targetHYear && $h_m == $targetHMonth); // Set Colors if ($currentDate == $todayStr) { $fontcolor = $todayfontcolor; $bgcellcolor = $todaybgcolor; } elseif ($isInHijriMonth) { $fontcolor = $defaultfontcolor; $bgcellcolor = $defaultbgcolor; } else { // Days outside the Hijri month (Greyed out) $fontcolor = "#CCCCCC"; $bgcellcolor = "#FFFFFF"; } $width = "14%"; if ($dayofweek == 0 || $dayofweek == 6) $width = "15%"; ?> <td bgcolor="<?= $bgcellcolor ?>" valign="middle" align="center" width="<?= $width ?>"> <?PHP if ($isInHijriMonth) { // Display Hijri Day prominently (Large), and Gregorian Day smaller in red below it echo "<font color=\"$fontcolor\" face=\"$fontfamily\" size=\"2\"><b>$h_d</b></font><br/>"; echo "<font color=\"red\" face=\"$fontfamily\" size=\"1\">$g_d</font>"; } else { // Display Gregorian day faded for days outside the Hijri month echo "<font color=\"$fontcolor\" face=\"$fontfamily\" size=\"1\">$g_d</font>"; } ?> </td> <?PHP // End row on Saturday if ($dayofweek == 6) { echo " </tr>\n"; $rowStarted = false; } // Move to next day $currentDate = date("Y-m-d", strtotime("$currentDate + 1 days")); } // Close row if loop ended unexpectedly if ($rowStarted) echo " </tr>\n"; ?> </table> </td> </tr> </table> </center> </div> يعرض شهر شوال عند فتح السكربت اقتباس
السؤال
محمد الحربي33
السلام عليكم
بالمرفقات وكما مبين في الصوره ملف بسيط يعرض جدول تاريخ الشهر الميلادي والهجري
لاكن عيبه انه يعرض الشهر الميلادي كاملا بداية من 1 الى نهاية الشهر الميلادي والمطلوب هو ان يعرض الشهر الهجري بداية من 1 الى نهاية الشهر
فهل من الممكن ذلك؟
icalendar2.zip
5 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.