PHP Calendar for pay stubs

Load pay stub links into dates

Page 1 of 1

10 Replies - 1271 Views - Last Post: 03 June 2010 - 04:40 PM Rate Topic: -----

#1 JordanH  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 46
  • Joined: 28-February 09

PHP Calendar for pay stubs

Posted 02 June 2010 - 05:40 AM

Hey everyone, I want to change the way our paystub webpage currently works. This is the code as of now.


<?php

global $user;

$dbhost=
$dbuser=
$dbpassword=
$dbname=drupal
$link=mysql_connect($dbhost,$dbuser,$dbpassword)or die                      ('Error connecting to mysql');
mysql_select_db($dbname, $link);



$query = "select value from profile_values where uid='" . $user->uid . "' and fid='2'";
$result = mysql_query($query);
$array = mysql_fetch_array($result);
$dir = 'paystubs/'.$array['value'];

mysql_close($link);
?>

	<h2>Month</h2>
	<ul>
	<?php
	monthlist($_GET['mon'],$dir);
	?>
	</ul>
	<h2><?php month($_GET['mon']);?>  Pay Stubs</h2>
	<?php
	if (file_exists($dir))
		{
		if ($dir_list = opendir($dir))
			{
			while(($filename = readdir($dir_list)) !== false)
				{ 
				if($filename !=".." && $filename !="." && (substr($filename,0,2) == $_GET['mon'] || substr($filename,1,2) == $_GET['mon']))
					{ 
					$cleanfilename = substr($filename, 0, strrpos($filename, '.')); 
					$dir_array[]=$cleanfilename;
					}
				}
			if(isset($dir_array))
				{
				sort($dir_array);
				foreach($dir_array as $value)
					{
					?>
					<p><a  target ="_blank" href="<?php echo $dir . "/" . $value; ?>"><?php echo $value;?></a></p>
					<?php
					}
				closedir($dir_list);
				}
			}
		}
	else
		{
		echo "Error finding file list";
		}
	?>

<?php
function monthlist($mon,$dir)
{
	$avail;
	if(file_exists($dir))
		{
		if($new_list = opendir($dir))
			{
			while(($filename = readdir($new_list)) !== false)
				{ 
				if($filename !=".." && $filename !=".")
					{ 
					$month[] = substr($filename,0,2);
					}
				}
			if(isset($month))
				{
				foreach($month as $value)
					{
					$avail[$value] = true;
					}
				}
			closedir($new_list);
			}
		}
	?>
	<?php if($avail['01']) { ?>
	<li><a href="?mon=01">January</a></li>
	<?php } if($avail['02']) { ?>
	<li><a href="?mon=02">February</a></li>
	<?php } if($avail['03']) { ?>
	<li><a href="?mon=03">March</a></li>
	<?php } if($avail['04']) { ?>
	<li><a href="?mon=04">April</a></li>
	<?php } if($avail['05']) { ?>
	<li><a href="?mon=05">May</a></li>
	<?php } if($avail['06']) { ?>
	<li><a href="?mon=06">June</a></li>
	<?php } if($avail['07']) { ?>
	<li><a href="?mon=07">July</a></li>
	<?php } if($avail['08']) { ?>
	<li><a href="?mon=08">August</a></li>
	<?php } if($avail['09']) { ?>
	<li><a href="?mon=09">September</a></li>
	<?php } if($avail['10']) { ?>
	<li><a href="?mon=10">October</a></li>
	<?php } if($avail['11']) { ?>
	<li><a href="?mon=11">November</a></li>
	<?php } if($avail['12']) { ?>
	<li><a href="?mon=12">December</a></li>
	<?php } return;
}


function month($mon)
{
	switch ($mon)
	{
	case "01":
		{
		echo "January";
		break;
		}
	case "02":
		{
		echo "February";
		break;
		}	
	case "03":
		{
		echo "March";
		break;
		}
	case "04":
		{
		echo "April";
		break;
		}	
	case "05":
		{
		echo "May";
		break;
		}	
	case "06":
		{
		echo "June";
		break;
		}	
	case "07":
		{
		echo "July";
		break;
		}
	case "08":
		{
		echo "August";
		break;
		}
	case "09":
		{
		echo "September";
		break;
		}
	case "10":
		{
		echo "October";
		break;
		}
	case "11":
		{
		echo "November";
		break;
		}	
	case "12":
		{
		echo "December";
		break;
		}		

	}
		
}
?>


Its ugly and ideally I would like to see a calendar where the user can select the month and year, the calendar loads the paystub information and creates links within the dates that there are paystubs for. Im not super proficient in php so im not really sure where to start, I found a calendar written in php here

I don't want anyone to do this for me but i could really use some direction here.

Thanks!,
Jordan

Is This A Good Question/Topic? 0
  • +

Replies To: PHP Calendar for pay stubs

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 06:25 AM

Some problems here:

1. The code you've posted is procedural, repetitive, and it makes no attempt to avoid redundant code. Example: your list of months should be in an array and output in a loop, and the month function is completely unnecessary, since echo $month[$number] would suffice.

2. IT'S NOT YOUR CODE!

3. You haven't posted any of YOUR code.

4. Items 2 and 3 sure make it seem like you do want somebody to do it for you.
Was This Post Helpful? 0
  • +
  • -

#3 JordanH  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 46
  • Joined: 28-February 09

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 06:49 AM

View PostCTphpnwb, on 02 June 2010 - 05:25 AM, said:

Some problems here:

1. The code you've posted is procedural, repetitive, and it makes no attempt to avoid redundant code. Example: your list of months should be in an array and output in a loop, and the month function is completely unnecessary, since echo $month[$number] would suffice.

2. IT'S NOT YOUR CODE!

3. You haven't posted any of YOUR code.

4. Items 2 and 3 sure make it seem like you do want somebody to do it for you.


Hmm, your right it isn't my code, in fact, none of it really is. I mean, I edited the code I posted to a degree but the author of that code is the person in my position before I worked here. I know its "procedural, repetitive, and it makes no attempt to avoid redundant code", thats why I want something different. I haven't posted any of my code because, as I said, I am NOT GOOD AT PHP. I have no code written so far, I don't even know where to begin working on this. Thats exactly why I came here, but I guess that was a mistake.

Even if I got an answer saying something like, "well you should learn A before you begin B", Or "I would start messing with X, then move to Y, and Z". I guess you proved me wrong though, im an incompetent asshole asking you to write all this code for me, I mean I didn't specifically say "I don't want anyone to do this for me but i could really use some direction here.".

Ill try not to judge all of DIC based on your ignorance but maybe I would be better of getting help somewhere else.

Thanks for nothing,
Jordan
Was This Post Helpful? -2
  • +
  • -

#4 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,221
  • Joined: 23-August 08

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 06:57 AM

JordanH, exactly what are you looking for in terms of "direction"? You do realize how vague that term is? I could say that one direction you might consider is actually learning PHP.
Was This Post Helpful? 2
  • +
  • -

#5 JordanH  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 46
  • Joined: 28-February 09

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 07:10 AM

View PostJackOfAllTrades, on 02 June 2010 - 05:57 AM, said:

JordanH, exactly what are you looking for in terms of "direction"? You do realize how vague that term is? I could say that one direction you might consider is actually learning PHP.


Sorry, I elaborate some more.

What im having trouble wrapping my head around is how I would go about getting the links to the pay stubs to show up in the calendar. There are folders on the webserver and they are all named by a certain employees id number. For instance all of Johns pay stubs are located in the folder "1234" because thats his employee ID. Furthermore, the pay stubs within those folders all all named by date. For example "01-15-2010.php".

I figured since there are already scripts for calendars written and I can edit the source code I could/should just take one and tailor it for my purpose. The problem is, Im not sure how/where to start because I don't know how to add the links. The first thing I would need to do is connect to the DB and get the currently logged in users employeeID so I know what folder to look in then I need to add the links for the pay stubs.
Was This Post Helpful? 0
  • +
  • -

#6 ShaneK  Icon User is offline

  • require_once("brain.php"); //Fatal error :/
  • member icon

Reputation: 239
  • View blog
  • Posts: 1,224
  • Joined: 10-May 09

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 08:12 AM

View PostJordanH, on 02 June 2010 - 07:10 AM, said:

View PostJackOfAllTrades, on 02 June 2010 - 05:57 AM, said:

JordanH, exactly what are you looking for in terms of "direction"? You do realize how vague that term is? I could say that one direction you might consider is actually learning PHP.


Sorry, I elaborate some more.

What im having trouble wrapping my head around is how I would go about getting the links to the pay stubs to show up in the calendar. There are folders on the webserver and they are all named by a certain employees id number. For instance all of Johns pay stubs are located in the folder "1234" because thats his employee ID. Furthermore, the pay stubs within those folders all all named by date. For example "01-15-2010.php".


In that case I'd suggest actually learning HTML. (And the basic layout information of servers...)

Quote

I figured since there are already scripts for calendars written and I can edit the source code I could/should just take one and tailor it for my purpose. The problem is, Im not sure how/where to start because I don't know how to add the links. The first thing I would need to do is connect to the DB and get the currently logged in users employeeID so I know what folder to look in then I need to add the links for the pay stubs.


And then PHP.

The stuff you're talking about is the most basic in web development. Tailoring a script is about your knowledge in PHP. Linking to stuff is about your knowledge in HTML. Databases are about your knowledge in PHP and whatever query language your database uses.

Yours,
Shane~

This post has been edited by ShaneK: 02 June 2010 - 08:15 AM

Was This Post Helpful? 1
  • +
  • -

#7 JordanH  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 46
  • Joined: 28-February 09

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 12:13 PM

View PostShaneK, on 02 June 2010 - 07:12 AM, said:

View PostJordanH, on 02 June 2010 - 07:10 AM, said:

View PostJackOfAllTrades, on 02 June 2010 - 05:57 AM, said:

JordanH, exactly what are you looking for in terms of "direction"? You do realize how vague that term is? I could say that one direction you might consider is actually learning PHP.


Sorry, I elaborate some more.

What im having trouble wrapping my head around is how I would go about getting the links to the pay stubs to show up in the calendar. There are folders on the webserver and they are all named by a certain employees id number. For instance all of Johns pay stubs are located in the folder "1234" because thats his employee ID. Furthermore, the pay stubs within those folders all all named by date. For example "01-15-2010.php".


In that case I'd suggest actually learning HTML. (And the basic layout information of servers...)

Quote

I figured since there are already scripts for calendars written and I can edit the source code I could/should just take one and tailor it for my purpose. The problem is, Im not sure how/where to start because I don't know how to add the links. The first thing I would need to do is connect to the DB and get the currently logged in users employeeID so I know what folder to look in then I need to add the links for the pay stubs.


And then PHP.

The stuff you're talking about is the most basic in web development. Tailoring a script is about your knowledge in PHP. Linking to stuff is about your knowledge in HTML. Databases are about your knowledge in PHP and whatever query language your database uses.

Yours,
Shane~


Alright, thanks I started an html/xhtml book/video today. I am familiar with c++ so that helps with php a little bit, hopefully I can get this going and if I need some more help ill be back.

Thanks,
Jordan
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 01:58 PM

View PostJordanH, on 02 June 2010 - 08:49 AM, said:

Even if I got an answer saying something like, "well you should learn A before you begin B", Or "I would start messing with X, then move to Y, and Z". I guess you proved me wrong though, im an incompetent asshole asking you to write all this code for me, I mean I didn't specifically say "I don't want anyone to do this for me but i could really use some direction here.".

Ill try not to judge all of DIC based on your ignorance but maybe I would be better of getting help somewhere else.

Thanks for nothing,
Jordan

Everything* you've done in this thread indicates that you do want some one to write it for you.


*With the exception of your claim that you don't want it written for you!
Was This Post Helpful? 0
  • +
  • -

#9 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: PHP Calendar for pay stubs

Posted 02 June 2010 - 05:24 PM

You asked for direction, so that would be for example, advice on how you could improve you script? Something like what CTphpnwb posted?

Quote

Example: your list of months should be in an array and output in a loop, and the month function is completely unnecessary, since echo $month[$number] would suffice.


That looks like pretty good advice to me, not to mention he is one of the most respected Experts around here, he didn't get the title of "PHP Expert" by being ignorant.

Also can I ask why you are trying to change this code which I will assume still works, even if it is messy, when you openly admit to not knowing PHP?

This post has been edited by KingCuddles: 02 June 2010 - 05:24 PM

Was This Post Helpful? 0
  • +
  • -

#10 JordanH  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 46
  • Joined: 28-February 09

Re: PHP Calendar for pay stubs

Posted 03 June 2010 - 06:27 AM

View PostCTphpnwb, on 02 June 2010 - 12:58 PM, said:

View PostJordanH, on 02 June 2010 - 08:49 AM, said:

Even if I got an answer saying something like, "well you should learn A before you begin B", Or "I would start messing with X, then move to Y, and Z". I guess you proved me wrong though, im an incompetent asshole asking you to write all this code for me, I mean I didn't specifically say "I don't want anyone to do this for me but i could really use some direction here.".

Ill try not to judge all of DIC based on your ignorance but maybe I would be better of getting help somewhere else.

Thanks for nothing,
Jordan

Everything* you've done in this thread indicates that you do want some one to write it for you.


*With the exception of your claim that you don't want it written for you!


How?

View PostKingCuddles, on 02 June 2010 - 04:24 PM, said:

You asked for direction, so that would be for example, advice on how you could improve you script? Something like what CTphpnwb posted?

Quote

Example: your list of months should be in an array and output in a loop, and the month function is completely unnecessary, since echo $month[$number] would suffice.


That looks like pretty good advice to me, not to mention he is one of the most respected Experts around here, he didn't get the title of "PHP Expert" by being ignorant.

Also can I ask why you are trying to change this code which I will assume still works, even if it is messy, when you openly admit to not knowing PHP?


I want the paystubs to appear as links in a calander instead of clicking on the word "May" and viewing every paystub from that month.
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: PHP Calendar for pay stubs

Posted 03 June 2010 - 04:40 PM

How? Are you serious? Just look at your last post!

Quote

I want the paystubs to appear as links in a calander instead of clicking on the word "May" and viewing every paystub from that month.

You state what you want, but nothing about what you have tried, and why it doesn't work. Honestly, from your first post I was tempted to close the topic for not following the rules. With each post you submit, I become more convinced that my first instinct was right.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1