Jump to content

atl_andy

Members
  • Posts

    141
  • Joined

  • Last visited

    Never

Everything posted by atl_andy

  1. Something more manageable from a data perspective might be: date userid unique_calls total_calls call_type 20-DEC-2009 123456 5 7 incoming 20-DEC-2009 123456 2 5 outgoing You would then do any calculations when data is selected from the db.
  2. I went with FPDF...no licensing issues. It took a couple of hours to get everything working, starting from scratch and never using it before. That's just working out a basic table layout and integrating an email function. Didn't check out PDFLib before going with FPDF.
  3. Here's another option for using one table, that holds all transactions together. Have a master transaction number that auto increments, JOU0001, JOU0002, etc. along with the transaction ID. Then you have a sequence number table for each transaction type, Sales sequence, Invoice sequence, which would populate a FK field to each table. SAL0001 linked to JOU0001, INV0001 linked to JOU0002, SAL0002 linked to INV0003. I work on a ERP system that uses this type of model for journal entries. It's quite a bit more complex since it has an inventory function that writes to the GL as well. Your best bet for data integrity would be to use one large table, IMHO.
  4. There should be a green button near the bottom of your screen that says "SOLVED", or something...click it.
  5. You have syntax issues...try: $sql="INSERT INTO people (fname, lname, username, password, joined, email, level) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[user]',sha1('$_POST[pass]'),'$date','$_POST[email]','norm')"; $result = mysql_query($sql); $sqlcheck="SELECT * FROM people WHERE username = '$_POST[user]' OR email = '$_POST[email]'"; $result = mysql_query($sqlcheck); $numrows = mysql_num_rows($result); check these links for the correct usage of INSERT and SELECT statements http://us.php.net/mysql_num_rows for using mysql_num_rows and http://us.php.net/manual/en/function.mysql-query.php for SELECT and INSERT statements
  6. thanks teamatomic, that worked <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link type="text/css" href="test.css" rel="stylesheet" /> </head> <body> <div id="img"> <img src="http://localhost/images/thumbs/tn.jpg" /> </div> </body> </html>
  7. I'm trying to figure out how Imagick works and, after searching Google, the only information I can find is a couple of tutorials. They don't get into the meat of the subject. I have been successful in reading a directory and writing a picture to a new directory. The issue I'm having is using the new picture after it is written to a directory. My simple example will create a thumbnail of a picture and display it on the screen. $dh = opendir('/var/www/images/'); while ($file = readdir($dh)) { if ($file != "." and $file != ".." and is_file($file)) { $img = new Imagick(); $img->readImage($file); if ($img) { $img->thumbnailImage(150,150, false); $img->writeImage('/var/www/images/thumbs/tn.jpg'); header("Content-type: image/jpg"); echo $img; } $img->destroy(); } } closedir($dh); But when I try to use the image, nothing displays: <img src="/var/www/images/tn.jpg" /> I'm not sure if it's a permissions issue, the new file is owned by the web server: -rw-r--r-- 1 www-data www-data 30895 2009-12-26 10:18 tn.jpg The file opens fine in GIMP. Any suggestions? My goal is to create an admin feature on a site so that images are uploaded and resized to thumbnails and displayed in a gallery. I would like to avoid using a 3rd party script so I can learn something new other than tweaking someone else's script.
  8. That was the problem. I figured the output would be in the cwd...guess not. It worked after I put in the absolute path.
  9. ok, I checked the permission on the path to the file and it was ok. As long as the file exists, it will be emailed. If the file doesn't exist, it won't be created. The issue has to be the PDF creation portion of the script. I'm stuck on how to proceed.
  10. The file is created and saved in /var/www. Required files, connection, and select query: #!/usr/bin/php -q -c <?php require('/var/www/html/admin/cdr/lib/fpdf.php'); require_once('/var/www/reports/Swift-4.0.5/lib/swift_required.php'); $conn=mysql_connect("localhost","user","pass"); mysql_select_db("asteriskcdrdb",$conn); if(!$conn) { echo "Cannot connect to db"; } // Select query $result=mysql_query("SELECT src,clid,dcontext,calldate FROM cdr WHERE dcontext='from-internal' AND calldate>=DATE_ADD(CURDATE(),INTERVAL -45 HOUR) AND calldate<=DATE_ADD(CURDATE(),INTERVAL -21 HOUR) ORDER BY src"); if(!$result) { echo "Cannot process query"; } PDF creation, save and email using Swift mailer class PDF extends FPDF { private $_yesterday1; // Page Header function Header() { // yesterday date $_yesterday1=date('m/d/Y',mktime(0,0,0,date("m"),date("d")-1,date("Y"))); // Arial bold 15 $this->SetFont('Arial','B',14); // Title $this->Cell(0,10,$_yesterday1,0,0,'C'); // Line Break $this->Ln(20); } } // Create a new PDF file $pdf = new PDF(); $pdf->AddPage(); // Field Name position $Y_Fields_Name_position = 20; // Table position, under Field Name position $Y_Table_Position = 26; // First create each field name // Gray color filling each Field Name box $pdf->SetFillColor(232,232,232); // Bold font for Field Name $pdf->SetFont('Arial','B',12); $pdf->SetY($Y_Fields_Name_position); $pdf->SetX(5); $pdf->Cell(45,6,'Sales Rep',1,0,'L',1); $pdf->SetX(50); $pdf->Cell(45,6,'Calls Made',1,0,'L',1); $pdf->Ln(); // Formulate call results while($row=mysql_fetch_object($result)) { if(preg_match("/Conor/",$row->clid) && preg_match("/2164/",$row->clid)) { $conor += 1; } if(preg_match("/Shon/",$row->clid) && preg_match("/7733/",$row->clid)) { $shon += 1; } // Show Conor; $pdf->SetFont('Arial','',12); $pdf->SetY($Y_Table_Position); $pdf->SetX(5); $pdf->MultiCell(45,6,"Conor",1); $pdf->SetY($Y_Table_Position); $pdf->SetX(50); $pdf->MultiCell(45,6,$conor,1); $pdf->SetY($Y_Table_Position); // Show Shon $pdf->SetFont('Arial','',12); $pdf->SetY($Y_Table_Position+6); $pdf->SetX(5); $pdf->MultiCell(45,6,"Shon",1); $pdf->SetY($Y_Table_Position+6); $pdf->SetX(50); $pdf->MultiCell(45,6,$shon,1); $pdf->SetY($Y_Table_Position+6); // yesterday date $yesterday=date('m/d/Y',mktime(0,0,0,date("m"),date("d")-1,date("Y"))); $pdf->Output("daily_report.pdf",'F'); // Create mail message $message = Swift_Message::newInstance() // Subject ->setSubject("Daily Call Report - " . $yesterday) // From address ->setFrom(array('email@email.com'=>'User')) // To address ->setTo(array('email@email.com'=>'User')) // Body ->setBody('Daily Call Report For ' . $yesterday) // Add attachment -> attach(Swift_Attachment::fromPath('/var/www/reports/daily_report.php')); // Create the transport $transport = Swift_MailTransport::newInstance(); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Send the message $numSent = $mailer->send($message); //printf("Sent %d messages\n", $numSent); //if ($mailer->send($message)) //{ echo "Sent\n"; } //else //{ echo "Failed\n"; }
  11. Hello, I have a PHP script that will create a PDF then email it as an attachment. Everything works great if I run the script manually from the command line. The PDF is created for the date range of the SQL query, and the email is sent to the recipients listed in the script. However, if I try to run the script in a cron job, only the email portion of the script will work; and that part will work only if the previous day's PDF is in the directory. Nothing will work if there is no file from the previous day ( I have tried to use unlink() to delete the file to prevent the previous day's email from being sent...unsuccessfully). Also, if the job runs on Tuesday and Wednesday, the PDF for Tuesday will be send each time. I'm baffled on which part of the system is not working and what to troubleshoot. I read, one a post somewhere, that to get cron to work with PHP the --enable-cgi flag might need to be set during compilation. This is running on an Asterisk server so there are no page visits that will allow the script to be run when a page is visited, or to use another web based cron-style application. I also checked the file permission and made the script executable. Cron job (I checked the logs and it runs without errors): 0 8 * * 1,2,3,4,5,6 /usr/bin/php -q /var/www/reports/reports.php Any help or insight would be appreciated. I can post code from the script if necessary, but I don't think that is the problem.
  12. Check out Swift mailer. It's an extremely simple-to-use PHP class. http://swiftmailer.org/
  13. I recently did some research on this, and here is what I use: 0 3 * * * 1,2,3,4,5,6 /usr/bin/php /var/www/test.php That will run every day at 3am. Change the 0 to a */5, and the 3 to a * to run it every 5 minutes. /usr/bin/php is the path to php and /var/www/test.php is the path to your file. Your paths may be different.
  14. I have a script running at 8am on a cron job. It uses Swift mailer to email a pdf document. If I run the script from the command line everything works great. But there are two issues when it is run using cron. The first issue is the file sent will not update to the current date, it just sends the previous day's pdf. The second issue was an attempt to get around the first. I used unlink to delete the file and touch to create it again, thinking that would eliminate the repeating file problem. To summarize, I need the script to get data from a mysql table that will be emailed in a pdf every morning via a cron job. The server is running CentOS 5.3 with LAMP. Here's the select statement: $result=mysql_query("SELECT src,clid,dcontext,calldate FROM cdr WHERE dcontext='from-internal' AND calldate>=DATE_ADD(CURDATE(),INTERVAL -21 HOUR) AND calldate<=DATE_ADD(CURDATE(),INTERVAL +3 HOUR) ORDER BY src"); Here's the cron job: 0 8 * * * 1,2,3,4,5,6 /usr/bin/php /var/www/reports/report.php Here's the mail portion on the script: // yesterday date $yesterday=date('m/d/Y',mktime(0,0,0,date("m"),date("d")-1,date("Y"))); $pdf->Output("daily_report.pdf",'F'); // Create mail message $message = Swift_Message::newInstance() // Subject ->setSubject("Daily Call Report - " . $yesterday) // From address ->setFrom(array('agriggs@impulsetech.us'=>'Andy Griggs')) // To address ->setTo(array('agriggs@impulsetech.us'=>'Andy Griggs')) // Body ->setBody('Daily Call Report For ' . $yesterday) // Add attachment -> attach(Swift_Attachment::fromPath('/var/www/reports/test.php')); // Create the transport $transport = Swift_MailTransport::newInstance(); // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); // Send the message $numSent = $mailer->send($message); // Delete the daily report file after emailing it unlink('daily_report.pdf'); // Create file so the cron job will work touch("/var/www/reports/daily_report.pdf"); Any help is greatly appreciated!
  15. It's a matter of preference. You can use a singleton for the connection or just a regular class that you use to open and close the connection. The only reason I mention the singleton is it's was my first "aha!" moment with design patterns, and it's really easy to implement. Opinions may differ... The following tutorial is available at: http://www.talkphp.com/advanced-php-programming/1304-how-use-singleton-design-pattern.html I changed it to reflect a connection instead of a query. Notice the constructor is private so it cannot be accesses outside the class. <?php // Example of a Singleton Database class class Database { // Store the single instance of Database private static $m_pInstance; // Private constructor to limit object instantiation to within the class private function __construct() { echo "Constructor called<br />\n"; } // Getter method for creating/returning the single instance of this class public static function getInstance() { if (!self::$m_pInstance) { self::$m_pInstance = new Database(); } return self::$m_pInstance; } // Test function to simulate a connection public function connection() { echo "Running query on database conenction...<br />\n"; } } // Wrap the test code in a function function testFunction() { // Get the single instance of the Database class using the gettor // method we created. Then call it's query method to output some text $pDatabase = Database::getInstance(); $pDatabase->connection(); } // Start the test testFunction(); testFunction(); // After running this script you will see that the constructor was only called // once, showing that only one instance of the class was created. ?>
  16. To start the GUI: startx To scroll up the cli output results, you need to pipe the results through less ls /etc | less It will scroll one page at a time using the space bar, q exits when you get to the end. Up and down arrows to go line-by-line. To copy files, you need to see where the USB drive is mounted. It could be in /media/sdb1. I can't remember exactly where RH mount, pretty sure it's on /media. Then just use cp to copy the files like any other copy.
  17. You may want to think about getting a distro that will have longer support, such as Ubuntu LTS (long term support) 8.04. It will be supported until 2013, since it was released last year. The install is basic, no GUI, but you can select a Samba server, web server, etc.
  18. Nice. What functionality are you building in, or have you built in? I've wanted to begin a project like that. I'm experienced on the operations side for procedures and such, just limited on the programming side. What language are you using?
  19. Apress has a Pro series for XHTML and CSS that is more of a reference than a tutorial. www.apress.com
  20. hostmonster.com is pretty damn easy to use. Unlimited disk storage, 100 mysql db's, unlimited domains, $6.95 a month. Cpanel is great too.
  21. I have worked with used Dell pc's for the last 8 years. Seagate is the best drive for the money. Very reliable, and a good warranty - 5 years. Any of their IDE 7200 rpm drives will work. Look on pricewatch.com to see what pricing is for them then go to a major retailer.
  22. Has anyone hear used any open source ERP solutions? My employer is implementing a new ERP system this year and we're using Sage X3, definitely not open source. Given my interest in open source I decided to google open source ERP. Surprisingly there are more than a few options and I wondered if anyone has used, or is using, one.
  23. Thanks for the reply. I've gone to the one error way that you suggested.
  24. Which is better to use for validation on the client, onblur or onchange? onblur does some wierd stuff if you tab off a field and tab back through. It will throw an error even though the value is valid. It's like it sends a blank value on the second tab. I have changed to onchange to avoid this issue, but wanted to get some opinions on which is the preferred method. ie, real world experience. <input type="text" id="email" name="email" size="25" maxlength="50" onblur="validateEmail();"/> function validateEmail() { var email = document.getElementById('email').value; if (email.length == 0) { var error ='<p class="error">Please enter your email address.</p>'; var replace = document.getElementById('error'); replace.innerHTML = error; return false; } if (email.length > 0) { var checkEmail = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/mgi.test( email ); if (checkEmail == false) { var error = '<p class="error">Please enter a valid email address.<br />eg. example@example.com</p>'; var replace = document.getElementById('error'); replace.innerHTML = error; return false; } } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.